fix(settings): decode subplebbit address with emoji to fix pathname

This commit is contained in:
Tom (plebeius.eth)
2024-05-31 19:59:08 +02:00
parent 1ecb2ba13d
commit 2ecedcc956
2 changed files with 13 additions and 6 deletions
+10
View File
@@ -44,6 +44,16 @@ export const isRulesView = (pathname: string, params: ParamsType): boolean => {
return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/rules`) : false;
};
export const isSettingsView = (pathname: string, params: ParamsType): boolean => {
const { subplebbitAddress, commentCid } = params;
const decodedPathname = decodeURIComponent(pathname);
return (
decodedPathname === `/p/${subplebbitAddress}/c/${commentCid}/settings` ||
decodedPathname === `/p/${subplebbitAddress}/description/settings` ||
decodedPathname === `/p/${subplebbitAddress}/rules/settings`
);
};
export const isSubscriptionsView = (pathname: string): boolean => {
return pathname.startsWith('/p/subscriptions');
};
+3 -6
View File
@@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next';
import { useComment, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { useLocation, useParams } from 'react-router-dom';
import styles from './post-page.module.css';
import { isDescriptionView, isRulesView } from '../../lib/utils/view-utils';
import { isDescriptionView, isRulesView, isSettingsView } from '../../lib/utils/view-utils';
import useReplyModal from '../../hooks/use-reply-modal';
import Post from '../../components/post';
import ReplyModal from '../../components/reply-modal';
@@ -16,10 +16,7 @@ const PostPage = () => {
const params = useParams();
const location = useLocation();
const { commentCid, subplebbitAddress } = params;
const showSettings =
location.pathname === `/p/${subplebbitAddress}/c/${commentCid}/settings` ||
location.pathname === `/p/${subplebbitAddress}/description/settings` ||
location.pathname === `/p/${subplebbitAddress}/rules/settings`;
const isInSettigsView = isSettingsView(location.pathname, params);
const isInDescriptionView = isDescriptionView(location.pathname, params);
const isInRulesView = isRulesView(location.pathname, params);
@@ -38,7 +35,7 @@ const PostPage = () => {
return (
<div className={styles.content}>
{showSettings && <SettingsModal />}
{isInSettigsView && <SettingsModal />}
{showReplyModal && activeCid && <ReplyModal closeModal={closeModal} parentCid={activeCid} scrollY={scrollY} />}
{isInDescriptionView ? (
<SubplebbitDescription