From 422ef01a9680fd608f9af41daa55594957791c1b Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Thu, 14 Dec 2023 14:52:20 +0100 Subject: [PATCH] feat(author): redirect to profile if author is account --- src/components/author-sidebar/author-sidebar.tsx | 4 ++-- .../post/comment-tools/mod-tools/mod-tools.tsx | 2 +- src/views/author/author.tsx | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/author-sidebar/author-sidebar.tsx b/src/components/author-sidebar/author-sidebar.tsx index f0b047c7..4deda831 100644 --- a/src/components/author-sidebar/author-sidebar.tsx +++ b/src/components/author-sidebar/author-sidebar.tsx @@ -56,13 +56,13 @@ const AuthorSidebar = () => { const { authorComments } = useAuthorComments({ authorAddress, commentCid }); const authorOldestCommentTimestamp = authorComments?.[0]?.timestamp || Date.now(); const authorSubplebbits = findAuthorSubplebbits(authorAddress, subplebbits.subplebbits); - + const estimatedAuthorKarma = estimateAuthorKarma(authorComments); const address = isAuthorPage ? params?.authorAddress : isProfilePage ? profileAccount?.author?.shortAddress : ''; const karma = isAuthorPage ? estimatedAuthorKarma : isProfilePage ? profileAccount?.karma : ''; const { postScore, replyScore } = karma || {}; - + const oldestCommentTimestamp = isAuthorPage ? authorOldestCommentTimestamp : isProfilePage ? profileOldestAccountTimestamp : Date.now(); const displayName = isAuthorPage ? authorAccount?.author?.displayName : isProfilePage ? profileAccount?.author?.displayName : ''; diff --git a/src/components/post/comment-tools/mod-tools/mod-tools.tsx b/src/components/post/comment-tools/mod-tools/mod-tools.tsx index e845cfe2..e9ace893 100644 --- a/src/components/post/comment-tools/mod-tools/mod-tools.tsx +++ b/src/components/post/comment-tools/mod-tools/mod-tools.tsx @@ -12,7 +12,7 @@ type ModToolsProps = { cid: string; }; -const ModTools = ({cid}: ModToolsProps) => { +const ModTools = ({ cid }: ModToolsProps) => { const { t } = useTranslation(); const post = useComment({ commentCid: cid }); const [isModToolsOpen, setIsModToolsOpen] = useState(false); diff --git a/src/views/author/author.tsx b/src/views/author/author.tsx index 1a8c7bff..c9792543 100644 --- a/src/views/author/author.tsx +++ b/src/views/author/author.tsx @@ -1,6 +1,6 @@ import { useEffect, useMemo, useRef } from 'react'; import { useLocation, useNavigate, useParams } from 'react-router-dom'; -import { useAuthorComments } from '@plebbit/plebbit-react-hooks'; +import { useAccount, useAuthorComments } from '@plebbit/plebbit-react-hooks'; import { StateSnapshot, Virtuoso, VirtuosoHandle } from 'react-virtuoso'; import { isAuthorCommentsView, isAuthorSubmittedView } from '../../lib/utils/view-utils'; import styles from './author.module.css'; @@ -12,6 +12,7 @@ import Reply from '../../components/reply/'; const lastVirtuosoStates: { [key: string]: StateSnapshot } = {}; const Author = () => { + const account = useAccount(); const location = useLocation(); const navigate = useNavigate(); const { authorAddress, commentCid, sortType } = useParams(); @@ -61,6 +62,13 @@ const Author = () => { } }, [authorAddress, lastCommentCid, commentCid, navigate]); + // redirect to profile if author is account + useEffect(() => { + if (authorAddress && account?.author?.address === authorAddress) { + navigate(`/profile`, { replace: true }); + } + }, [authorAddress, account, navigate]); + return (