From dcd29a46bb4032a3de934f3409a643a5dd5b3e5c Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Tue, 2 Apr 2024 17:00:36 +0200 Subject: [PATCH] feat(app): add post page --- src/app.tsx | 2 + src/components/post/post.tsx | 206 ++++++++++++----------- src/views/post-page/index.ts | 1 + src/views/post-page/post-page.module.css | 0 src/views/post-page/post-page.tsx | 19 +++ 5 files changed, 126 insertions(+), 102 deletions(-) create mode 100644 src/views/post-page/index.ts create mode 100644 src/views/post-page/post-page.module.css create mode 100644 src/views/post-page/post-page.tsx diff --git a/src/app.tsx b/src/app.tsx index b86c0056..dc4e1f76 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -6,6 +6,7 @@ import { useDefaultSubplebbitAddresses } from './hooks/use-default-subplebbits'; import useTheme from './hooks/use-theme'; import styles from './app.module.css'; import Home from './views/home'; +import PostPage from './views/post-page'; import Settings from './views/settings'; import Subplebbit from './views/subplebbit'; import BoardNav from './components/board-nav'; @@ -67,6 +68,7 @@ const App = () => { } /> }> } /> + } /> } /> diff --git a/src/components/post/post.tsx b/src/components/post/post.tsx index 8d450319..de5f89ee 100644 --- a/src/components/post/post.tsx +++ b/src/components/post/post.tsx @@ -10,7 +10,7 @@ import styles from './post.module.css'; import Markdown from '../markdown'; import Media from '../media'; -const ReplyDesktop = ({ index, reply }: { index: number; reply: Comment }) => { +const ReplyDesktop = ({ reply }: Comment) => { const { t } = useTranslation(); const { author, content, link, linkHeight, linkWidth, pinned, shortCid, subplebbitAddress, timestamp } = reply || {}; const { displayName, shortAddress } = author || {}; @@ -20,79 +20,77 @@ const ReplyDesktop = ({ index, reply }: { index: number; reply: Comment }) => { const [showThumbnail, setShowThumbnail] = useState(true); return ( - index < 5 && ( -
-
{'>>'}
-
-
- - - - - {displayName || 'Anonymous'} - (u/{shortAddress}) - - {getFormattedDate(timestamp)} - - - - c/ - - - {shortCid} - +
+
{'>>'}
+
+
+ + + + + {displayName || 'Anonymous'} + (u/{shortAddress}) + + {getFormattedDate(timestamp)} + + + + c/ + + + {shortCid} - {pinned && ( - - - - )} - -
- {link && ( -
-
- {t('link')}:{' '} - - {link.length > 30 ? link.slice(0, 30) + '...' : link} - - {!showThumbnail && (commentMediaInfo?.type === 'iframe' || commentMediaInfo?.type === 'video') && ( - - {' '} - [ - setShowThumbnail(true)}> - {t('close')} - - ] + {pinned && ( + + + + )} + + +
+ {link && ( +
+
+ {t('link')}:{' '} + + {link.length > 30 ? link.slice(0, 30) + '...' : link} + + {!showThumbnail && (commentMediaInfo?.type === 'iframe' || commentMediaInfo?.type === 'video') && ( + + {' '} + [ + setShowThumbnail(true)}> + {t('close')} - )} -
- {hasThumbnail && ( - + ] + )}
- )} - {content && ( -
- -
- )} -
+ {hasThumbnail && ( + + )} +
+ )} + {content && ( +
+ +
+ )}
- ) +
); }; -const PostDesktop = ({ post }: Comment) => { +const PostDesktop = ({ post, showAllReplies }: { post: Comment; showAllReplies: boolean }) => { const { t } = useTranslation(); const { author, cid, content, link, linkHeight, linkWidth, locked, pinned, postCid, replyCount, shortCid, subplebbitAddress, timestamp, title } = post || {}; const { displayName, shortAddress } = author || {}; @@ -206,7 +204,7 @@ const PostDesktop = ({ post }: Comment) => { )} {!pinned && - replies.map((reply, index) => ( + replies.slice(0, showAllReplies ? replies.length : 5).map((reply, index) => (
@@ -215,7 +213,7 @@ const PostDesktop = ({ post }: Comment) => { ); }; -const ReplyMobile = ({ index, reply }: { index: number; reply: Comment }) => { +const ReplyMobile = ({ reply }: Comment) => { const { author, content, link, linkHeight, linkWidth, pinned, shortCid, subplebbitAddress, timestamp } = reply || {}; const { displayName, shortAddress } = author || {}; @@ -224,43 +222,41 @@ const ReplyMobile = ({ index, reply }: { index: number; reply: Comment }) => { const [showThumbnail, setShowThumbnail] = useState(true); return ( - index < 5 && ( -
-
-
-
- ... - - {displayName || 'Anonymous'} - (u/{shortAddress}) - - - {getFormattedDate(timestamp)} c/ - {shortCid} - -
- {hasThumbnail && ( - - )} -
- -
+
+
+
+
+ ... + + {displayName || 'Anonymous'} + (u/{shortAddress}) + + + {getFormattedDate(timestamp)} c/ + {shortCid} +
+ {hasThumbnail && ( + + )} +
+ +
- ) +
); }; -const PostMobile = ({ post }: Comment) => { +const PostMobile = ({ post, showAllReplies }: { post: Comment; showAllReplies: boolean }) => { const { author, cid, content, link, linkHeight, linkWidth, pinned, replyCount, shortCid, subplebbitAddress, timestamp, title } = post || {}; const { address, displayName, shortAddress } = author || {}; const linkCount = useCountLinksInReplies(post); @@ -334,7 +330,7 @@ const PostMobile = ({ post }: Comment) => {
{!pinned && - replies.map((reply, index) => ( + replies.slice(0, showAllReplies ? replies.length : 5).map((reply, index) => (
@@ -344,12 +340,18 @@ const PostMobile = ({ post }: Comment) => { ); }; -const Post = ({ post }: Comment) => { +interface PostProps { + index?: number; + post: Comment; + showAllReplies?: boolean; +} + +const Post = ({ post, showAllReplies = false }: PostProps) => { return (
- - + +
); diff --git a/src/views/post-page/index.ts b/src/views/post-page/index.ts new file mode 100644 index 00000000..223b2106 --- /dev/null +++ b/src/views/post-page/index.ts @@ -0,0 +1 @@ +export { default } from './post-page'; diff --git a/src/views/post-page/post-page.module.css b/src/views/post-page/post-page.module.css new file mode 100644 index 00000000..e69de29b diff --git a/src/views/post-page/post-page.tsx b/src/views/post-page/post-page.tsx new file mode 100644 index 00000000..56be8b03 --- /dev/null +++ b/src/views/post-page/post-page.tsx @@ -0,0 +1,19 @@ +import { useComment } from '@plebbit/plebbit-react-hooks'; +import { useParams } from 'react-router-dom'; +import Post from '../../components/post/post'; +import styles from './post-page.module.css'; + +const PostPage = () => { + const params = useParams(); + const { commentCid } = params; + + const post = useComment({ commentCid }); + + return ( +
+ +
+ ); +}; + +export default PostPage;