mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(pending post): invalid pending post index would break the view, redirect to not found instead
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
||||
import { useAccountComment } from '@plebbit/plebbit-react-hooks';
|
||||
import { useAccountComment, useAccountComments } from '@plebbit/plebbit-react-hooks';
|
||||
import { isSettingsView } from '../../lib/utils/view-utils';
|
||||
import { Post } from '../post';
|
||||
import SettingsModal from '../../components/settings-modal';
|
||||
|
||||
const PendingPost = () => {
|
||||
const { accountComments } = useAccountComments();
|
||||
const { accountCommentIndex } = useParams<{ accountCommentIndex?: string }>();
|
||||
const commentIndex = accountCommentIndex ? parseInt(accountCommentIndex) : undefined;
|
||||
const post = useAccountComment({ commentIndex });
|
||||
@@ -16,6 +17,19 @@ const PendingPost = () => {
|
||||
|
||||
useEffect(() => window.scrollTo(0, 0), []);
|
||||
|
||||
const isValidAccountCommentIndex =
|
||||
!accountCommentIndex ||
|
||||
(!isNaN(parseInt(accountCommentIndex)) &&
|
||||
parseInt(accountCommentIndex) >= 0 &&
|
||||
accountComments?.length > 0 &&
|
||||
parseInt(accountCommentIndex) < accountComments.length);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isValidAccountCommentIndex) {
|
||||
navigate('/not-found', { replace: true });
|
||||
}
|
||||
}, [isValidAccountCommentIndex, navigate]);
|
||||
|
||||
useEffect(() => {
|
||||
if (post?.cid && post?.subplebbitAddress) {
|
||||
navigate(`/p/${post?.subplebbitAddress}/c/${post?.cid}`, { replace: true });
|
||||
|
||||
Reference in New Issue
Block a user