fix catalog button link

This commit is contained in:
plebeius.eth
2024-05-17 21:27:06 +02:00
parent 09f05ac8a0
commit f189b8ca12
3 changed files with 17 additions and 9 deletions
+12 -6
View File
@@ -1,5 +1,5 @@
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'; import { Link, useLocation, useParams } from 'react-router-dom';
import { useAccountComment, useSubscribe } from '@plebbit/plebbit-react-hooks'; import { useAccountComment, useSubscribe } from '@plebbit/plebbit-react-hooks';
import styles from './board-buttons.module.css'; import styles from './board-buttons.module.css';
import { isAllView, isCatalogView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils'; import { isAllView, isCatalogView, isPendingPostView, isPostPageView, isSubscriptionsView } from '../../lib/utils/view-utils';
@@ -16,12 +16,18 @@ const OptionsButton = () => {
return <button className='button'>{t('options')}</button>; return <button className='button'>{t('options')}</button>;
}; };
const CatalogButton = ({ address, isInAllView, isInCatalogView, isInSubscriptionsView }: BoardButtonsProps) => { const CatalogButton = ({ address, isInAllView, isInCatalogView }: BoardButtonsProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const navigate = useNavigate();
const link = isInAllView ? `/p/all/catalog` : isInSubscriptionsView ? `/p/subscriptions/catalog` : isInCatalogView ? `/p/${address}` : `/p/${address}/catalog`;
return <button className='button'>{isInCatalogView ? <span onClick={() => navigate(-1)}>{t('return')}</span> : <Link to={link}>{t('catalog')}</Link>}</button>; return (
<button className='button'>
{isInCatalogView ? (
<Link to={isInAllView ? '/p/all' : `/p/${address}`}>{t('return')}</Link>
) : (
<Link to={isInAllView ? `/p/all/catalog` : `/p/${address}/catalog`}>{t('catalog')}</Link>
)}
</button>
);
}; };
const SubscribeButton = ({ address }: BoardButtonsProps) => { const SubscribeButton = ({ address }: BoardButtonsProps) => {
@@ -70,7 +76,7 @@ export const MobileBoardButtons = () => {
{isInPostView || isInPendingPostPage ? ( {isInPostView || isInPendingPostPage ? (
<div className={styles.mobilePostPageButtons}> <div className={styles.mobilePostPageButtons}>
<ReturnButton address={subplebbitAddress} /> <ReturnButton address={subplebbitAddress} />
<CatalogButton address={subplebbitAddress} /> <CatalogButton address={subplebbitAddress} isInAllView={isInAllView} />
<BottomButton /> <BottomButton />
<div className={styles.mobilePostPageButtonsSecondRow}> <div className={styles.mobilePostPageButtonsSecondRow}>
<OptionsButton /> <OptionsButton />
-2
View File
@@ -8,7 +8,6 @@ import useDefaultSubplebbits, { categorizeSubplebbits, useDefaultSubplebbitAddre
const BoardNavDesktop = () => { const BoardNavDesktop = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const location = useLocation(); const location = useLocation();
const params = useParams();
const isInCatalogView = isCatalogView(location.pathname); const isInCatalogView = isCatalogView(location.pathname);
const subplebbits = useDefaultSubplebbits(); const subplebbits = useDefaultSubplebbits();
@@ -47,7 +46,6 @@ const BoardNavMobile = ({ subplebbitAddress }: { subplebbitAddress: string }) =>
const currentSubplebbitIsInList = subplebbitAddresses.some((address: string) => address === subplebbitAddress); const currentSubplebbitIsInList = subplebbitAddresses.some((address: string) => address === subplebbitAddress);
const location = useLocation(); const location = useLocation();
const params = useParams();
const isInAllView = isAllView(location.pathname); const isInAllView = isAllView(location.pathname);
const isInCatalogView = isCatalogView(location.pathname); const isInCatalogView = isCatalogView(location.pathname);
const isInSubscriptionsView = isSubscriptionsView(location.pathname); const isInSubscriptionsView = isSubscriptionsView(location.pathname);
@@ -164,6 +164,7 @@ const PostMobile = ({ openReplyModal, post, roles, showAllReplies }: PostProps)
const params = useParams(); const params = useParams();
const location = useLocation(); const location = useLocation();
const isInAllView = isAllView(location.pathname);
const isInPendingPostView = isPendingPostView(location.pathname, params); const isInPendingPostView = isPendingPostView(location.pathname, params);
const isInPostView = isPostPageView(location.pathname, params); const isInPostView = isPostPageView(location.pathname, params);
@@ -188,7 +189,10 @@ const PostMobile = ({ openReplyModal, post, roles, showAllReplies }: PostProps)
{replyCount > 0 && `${replyCount} Replies`} {replyCount > 0 && `${replyCount} Replies`}
{linksCount > 0 && ` / ${linksCount} Links`} {linksCount > 0 && ` / ${linksCount} Links`}
</span> </span>
<Link to={`/p/${subplebbitAddress}/${isDescription ? 'description' : isRules ? 'rules' : `c/${cid}`}`} className='button'> <Link
to={isInAllView && isDescription ? '/p/all/description' : `/p/${subplebbitAddress}/${isDescription ? 'description' : isRules ? 'rules' : `c/${cid}`}`}
className='button'
>
{t('view_thread')} {t('view_thread')}
</Link> </Link>
</div> </div>