2024-05-16 23:05:00 +02:00
|
|
|
import { useLocation, useParams } from 'react-router-dom';
|
|
|
|
|
import { Role, useSubplebbit } from '@plebbit/plebbit-react-hooks';
|
2024-05-06 22:49:55 +02:00
|
|
|
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';
|
2024-05-16 23:05:00 +02:00
|
|
|
import PostDesktop from './post-desktop';
|
|
|
|
|
import PostMobile from './post-mobile';
|
2024-03-29 13:54:11 +01:00
|
|
|
|
2024-05-16 23:05:00 +02:00
|
|
|
export interface PostProps {
|
2024-04-08 16:03:32 +02:00
|
|
|
index?: number;
|
2024-05-16 18:15:48 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2024-04-29 12:05:52 +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
|
|
|
|
2024-05-16 18:15:48 +02:00
|
|
|
const params = useParams();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const isInPostPage = isPostPageView(location.pathname, params);
|
|
|
|
|
const isPendingPostPage = isPendingPostView(location.pathname, params);
|
|
|
|
|
|
2024-03-27 15:10:58 +01:00
|
|
|
return (
|
|
|
|
|
<div className={styles.thread}>
|
|
|
|
|
<div className={styles.postContainer}>
|
2024-04-10 13:16:07 +02:00
|
|
|
{isMobile ? (
|
2024-05-16 18:15:48 +02:00
|
|
|
<PostMobile
|
|
|
|
|
isInPostPage={isInPostPage}
|
|
|
|
|
isPendingPostPage={isPendingPostPage}
|
|
|
|
|
post={post}
|
|
|
|
|
roles={subplebbit?.roles}
|
|
|
|
|
showAllReplies={showAllReplies}
|
|
|
|
|
openReplyModal={openReplyModal}
|
|
|
|
|
/>
|
2024-04-10 13:16:07 +02:00
|
|
|
) : (
|
2024-05-16 18:15:48 +02:00
|
|
|
<PostDesktop
|
|
|
|
|
isInPostPage={isInPostPage}
|
|
|
|
|
isPendingPostPage={isPendingPostPage}
|
|
|
|
|
post={post}
|
|
|
|
|
roles={subplebbit?.roles}
|
|
|
|
|
showAllReplies={showAllReplies}
|
|
|
|
|
openReplyModal={openReplyModal}
|
|
|
|
|
/>
|
2024-04-10 13:16:07 +02:00
|
|
|
)}
|
2024-03-27 15:10:58 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-22 15:31:02 +01:00
|
|
|
export default Post;
|