feat(post): redirect to post view when cid is received for pending post

This commit is contained in:
plebeius.eth
2023-12-22 11:33:09 +01:00
parent 853d88a0b9
commit ef1b385709

View File

@@ -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 || {};