feat(author): redirect to profile if author is account

This commit is contained in:
plebeius.eth
2023-12-14 14:52:20 +01:00
parent 73c99029a4
commit 422ef01a96
3 changed files with 12 additions and 4 deletions

View File

@@ -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 : '';

View File

@@ -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);

View File

@@ -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 (
<div className={styles.content}>
<div className={styles.sidebar}>