From ef1b38570929f69cb8d2bb5627a2039ef4609665 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Fri, 22 Dec 2023 11:33:09 +0100 Subject: [PATCH] feat(post): redirect to post view when cid is received for pending post --- src/views/post/post.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/views/post/post.tsx b/src/views/post/post.tsx index 8dad4b41..3535b11d 100644 --- a/src/views/post/post.tsx +++ b/src/views/post/post.tsx @@ -1,5 +1,5 @@ import { useEffect } from 'react'; -import { useLocation, useParams } from 'react-router-dom'; +import { useLocation, useNavigate, useParams } from 'react-router-dom'; import { useAccountComment, useComment, useSubplebbit } from '@plebbit/plebbit-react-hooks'; import { useTranslation } from 'react-i18next'; import styles from './post.module.css'; @@ -22,6 +22,14 @@ const Post = () => { const pendingPost = useAccountComment({ commentIndex: params?.accountCommentIndex as any }); const post = isPendingPage ? pendingPost : comment; + // in pending page, redirect to post view when post.cid is received + const navigate = useNavigate(); + useEffect(() => { + if (post?.cid && post?.subplebbitAddress) { + navigate(`/p/${post?.subplebbitAddress}/c/${post?.cid}`, { replace: true }); + } + }, [post?.cid, post?.subplebbitAddress, navigate]); + const { cid, downvoteCount, replyCount, subplebbitAddress, timestamp, title, upvoteCount } = comment || {}; const subplebbit = useSubplebbit({ subplebbitAddress }); const { createdAt, description, roles, rules, updatedAt } = subplebbit || {};