From 2ecedcc956b456b84966b8e1a148a878af8a083b Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Fri, 31 May 2024 19:59:08 +0200 Subject: [PATCH] fix(settings): decode subplebbit address with emoji to fix pathname --- src/lib/utils/view-utils.ts | 10 ++++++++++ src/views/post-page/post-page.tsx | 9 +++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib/utils/view-utils.ts b/src/lib/utils/view-utils.ts index 1f3918a4..080d19ec 100644 --- a/src/lib/utils/view-utils.ts +++ b/src/lib/utils/view-utils.ts @@ -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'); }; diff --git a/src/views/post-page/post-page.tsx b/src/views/post-page/post-page.tsx index 521f5ea0..bd71a3b5 100644 --- a/src/views/post-page/post-page.tsx +++ b/src/views/post-page/post-page.tsx @@ -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 (
- {showSettings && } + {isInSettigsView && } {showReplyModal && activeCid && } {isInDescriptionView ? (