Files
5chan/src/components/post/post.tsx
T

57 lines
1.7 KiB
TypeScript
Raw Normal View History

import { useLocation, useParams } from 'react-router-dom';
import { Role, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { isPendingPostView, isPostPageView } from '../../lib/utils/view-utils';
2024-04-10 13:16:07 +02:00
import useWindowWidth from '../../hooks/use-window-width';
2024-03-29 13:54:11 +01:00
import styles from './post.module.css';
import PostDesktop from './post-desktop';
import PostMobile from './post-mobile';
2024-03-29 13:54:11 +01:00
export interface PostProps {
2024-04-08 16:03:32 +02:00
index?: number;
isInPostPage?: boolean;
isPendingPostPage?: boolean;
2024-04-08 16:03:32 +02:00
post?: any;
reply?: any;
roles?: Role[];
showAllReplies?: boolean;
2024-04-28 20:08:41 +02:00
openReplyModal?: (cid: string) => void;
2024-04-08 16:03:32 +02:00
}
const Post = ({ post, showAllReplies = false, openReplyModal }: PostProps) => {
2024-04-08 16:03:32 +02:00
const subplebbit = useSubplebbit({ subplebbitAddress: post?.subplebbitAddress });
2024-04-10 13:16:07 +02:00
const isMobile = useWindowWidth() < 640;
2024-04-28 20:08:41 +02:00
const params = useParams();
const location = useLocation();
const isInPostPage = isPostPageView(location.pathname, params);
const isPendingPostPage = isPendingPostView(location.pathname, params);
return (
<div className={styles.thread}>
<div className={styles.postContainer}>
2024-04-10 13:16:07 +02:00
{isMobile ? (
<PostMobile
isInPostPage={isInPostPage}
isPendingPostPage={isPendingPostPage}
post={post}
roles={subplebbit?.roles}
showAllReplies={showAllReplies}
openReplyModal={openReplyModal}
/>
2024-04-10 13:16:07 +02:00
) : (
<PostDesktop
isInPostPage={isInPostPage}
isPendingPostPage={isPendingPostPage}
post={post}
roles={subplebbit?.roles}
showAllReplies={showAllReplies}
openReplyModal={openReplyModal}
/>
2024-04-10 13:16:07 +02:00
)}
</div>
</div>
);
};
2024-03-22 15:31:02 +01:00
export default Post;