From 5dcfc8fecece68cc1ffbfd5394b98c28a466be9e Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Thu, 5 Dec 2024 14:49:39 +0100 Subject: [PATCH] rename variables --- src/components/header/header.tsx | 31 +++++++++++++++-------------- src/components/post/post.tsx | 21 +++++++++---------- src/components/reply/reply.tsx | 8 ++++---- src/components/sidebar/sidebar.tsx | 14 ++++++------- src/hooks/use-comment-media-info.ts | 10 +++++----- src/lib/utils/view-utils.ts | 4 ++-- src/views/post-page/post-page.tsx | 6 +++--- 7 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/components/header/header.tsx b/src/components/header/header.tsx index 96bf87ec..e249cd44 100644 --- a/src/components/header/header.tsx +++ b/src/components/header/header.tsx @@ -15,8 +15,8 @@ import { isHomeAboutView, isHomeView, isInboxView, - isPendingView, - isPostView, + isPendingPostView, + isPostPageView, isProfileView, isProfileCommentsView, isProfileDownvotedView, @@ -62,11 +62,11 @@ const CommentsButton = () => { const { t } = useTranslation(); const params = useParams(); const location = useLocation(); - const isInPostView = isPostView(location.pathname, params); + const isInPostPageView = isPostPageView(location.pathname, params); const isInHomeAboutView = isHomeAboutView(location.pathname); return ( -
  • +
  • {t('comments')}
  • ); @@ -242,8 +242,8 @@ const HeaderTabs = () => { const isInHomeAboutView = isHomeAboutView(location.pathname); const isInHomeView = isHomeView(location.pathname); const isInInboxView = isInboxView(location.pathname); - const isInPendingView = isPendingView(location.pathname, params); - const isInPostView = isPostView(location.pathname, params); + const isInPendingPostView = isPendingPostView(location.pathname, params); + const isInPostPageView = isPostPageView(location.pathname, params); const isInProfileView = isProfileView(location.pathname); const isInSubplebbitView = isSubplebbitView(location.pathname, params); const isInSubplebbitSettingsView = isSubplebbitSettingsView(location.pathname, params); @@ -253,13 +253,13 @@ const HeaderTabs = () => { const isInSettingsView = isSettingsView(location.pathname); const isInSettingsPlebbitOptionsView = isSettingsPlebbitOptionsView(location.pathname); - if (isInPostView) { + if (isInPostPageView) { return ; } else if (isInHomeView || isInHomeAboutView || (isInSubplebbitView && !isInSubplebbitSubmitView && !isInSubplebbitSettingsView) || isInAllView) { return ; - } else if ((isInProfileView || isInAuthorView) && !isInPendingView) { + } else if ((isInProfileView || isInAuthorView) && !isInPendingPostView) { return ; - } else if (isInPendingView) { + } else if (isInPendingPostView) { return {t('pending')}; } else if (isInInboxView) { return ; @@ -279,7 +279,7 @@ const HeaderTitle = ({ title, shortAddress }: { title: string; shortAddress: str const isInAllView = isAllView(location.pathname); const isInAuthorView = isAuthorView(location.pathname); const isInInboxView = isInboxView(location.pathname); - const isInPostView = isPostView(location.pathname, params); + const isInPostPageView = isPostPageView(location.pathname, params); const isInProfileView = isProfileView(location.pathname); const isInSettingsView = isSettingsView(location.pathname); const isInSettingsPlebbitOptionsView = isSettingsPlebbitOptionsView(location.pathname); @@ -302,7 +302,7 @@ const HeaderTitle = ({ title, shortAddress }: { title: string; shortAddress: str {subplebbitTitle}: {submitTitle} ); - } else if (isInPostView || (isInSubplebbitView && !isInSubplebbitSettingsView)) { + } else if (isInPostPageView || (isInSubplebbitView && !isInSubplebbitSettingsView)) { return subplebbitTitle; } else if (isInSubplebbitSettingsView) { return ( @@ -346,7 +346,7 @@ const Header = () => { const isInHomeView = isHomeView(location.pathname); const isInHomeAboutView = isHomeAboutView(location.pathname); const isInInboxView = isInboxView(location.pathname); - const isInPostView = isPostView(location.pathname, params); + const isInPostPageView = isPostPageView(location.pathname, params); const isInProfileView = isProfileView(location.pathname); const isInSettingsView = isSettingsView(location.pathname); const isInSubplebbitView = isSubplebbitView(location.pathname, params); @@ -356,11 +356,12 @@ const Header = () => { const isInSubplebbitSettingsView = isSubplebbitSettingsView(location.pathname, params); const isInNotFoundView = useNotFoundStore((state) => state.isNotFound); - const hasFewTabs = isInPostView || isInSubmitView || isInSubplebbitSubmitView || isInSubplebbitSettingsView || isInSettingsView || isInInboxView || isInSettingsView; + const hasFewTabs = + isInPostPageView || isInSubmitView || isInSubplebbitSubmitView || isInSubplebbitSettingsView || isInSettingsView || isInInboxView || isInSettingsView; const hasStickyHeader = isInHomeView || isInNotFoundView || - (isInSubplebbitView && !isInSubplebbitSubmitView && !isInSubplebbitSettingsView && !isInPostView && !isInHomeAboutView && !isInSubplebbitAboutView) || + (isInSubplebbitView && !isInSubplebbitSubmitView && !isInSubplebbitSettingsView && !isInPostPageView && !isInHomeAboutView && !isInSubplebbitAboutView) || (isInProfileView && !isInHomeAboutView) || (isInAllView && !isInAllAboutView) || (isInAuthorView && !isInHomeAboutView); @@ -405,7 +406,7 @@ const Header = () => { {isMobile && !isInSubplebbitSubmitView && (
      - {(isInHomeView || isInHomeAboutView || isInSubplebbitView || isInHomeAboutView || isInAllView || isInPostView) && } + {(isInHomeView || isInHomeAboutView || isInSubplebbitView || isInHomeAboutView || isInAllView || isInPostPageView) && }
    )} diff --git a/src/components/post/post.tsx b/src/components/post/post.tsx index f4174846..b07453d4 100644 --- a/src/components/post/post.tsx +++ b/src/components/post/post.tsx @@ -3,7 +3,7 @@ import styles from './post.module.css'; import { Link, useLocation, useParams } from 'react-router-dom'; import { Comment, useAuthorAddress, useBlock, useComment, useEditedComment, useSubplebbit, useSubscribe } from '@plebbit/plebbit-react-hooks'; import { useTranslation } from 'react-i18next'; -import { isAllView, isPostView, isProfileHiddenView, isSubplebbitView } from '../../lib/utils/view-utils'; +import { isAllView, isPostPageView, isProfileHiddenView, isSubplebbitView } from '../../lib/utils/view-utils'; import { getHasThumbnail } from '../../lib/utils/media-utils'; import { getPostScore } from '../../lib/utils/post-utils'; import { getHostname } from '../../lib/utils/url-utils'; @@ -117,13 +117,13 @@ const Post = ({ index, post = {} }: PostProps) => { const authorRole = subplebbit?.roles?.[post.author?.address]?.role; const isInAllView = isAllView(location.pathname); - const isInPostView = isPostView(location.pathname, params); + const isInPostPageView = isPostPageView(location.pathname, params); const isInProfileHiddenView = isProfileHiddenView(location.pathname); const isInSubplebbitView = isSubplebbitView(location.pathname, params); const commentMediaInfo = useCommentMediaInfo(post); - const [isExpanded, setIsExpanded] = useState(isInPostView); + const [isExpanded, setIsExpanded] = useState(isInPostPageView); const toggleExpanded = () => setIsExpanded(!isExpanded); const [isEditing, setIsEditing] = useState(false); @@ -137,7 +137,7 @@ const Post = ({ index, post = {} }: PostProps) => { const hasThumbnail = getHasThumbnail(commentMediaInfo, link); const linkUrl = getHostname(link); - const linkClass = `${isInPostView ? (link ? styles.externalLink : styles.internalLink) : styles.link} ${pinned ? styles.pinnedLink : ''}`; + const linkClass = `${isInPostPageView ? (link ? styles.externalLink : styles.internalLink) : styles.link} ${pinned ? styles.pinnedLink : ''}`; const { blocked, unblock } = useBlock({ cid }); @@ -145,7 +145,7 @@ const Post = ({ index, post = {} }: PostProps) => { const { subscribe, subscribed } = useSubscribe({ subplebbitAddress }); // show gray dotted border around last clicked post - const isLastClicked = sessionStorage.getItem('lastClickedPost') === cid && !isInPostView; + const isLastClicked = sessionStorage.getItem('lastClickedPost') === cid && !isInPostPageView; const handlePostClick = () => { if (cid) { if (sessionStorage.getItem('lastClickedPost') === cid) { @@ -177,7 +177,7 @@ const Post = ({ index, post = {} }: PostProps) => {
    cid && downvote()} />
    - {hasThumbnail && (!isInPostView || commentMediaInfo?.type === 'webpage') && !spoiler && ( + {hasThumbnail && (!isInPostPageView || commentMediaInfo?.type === 'webpage') && !spoiler && ( {
    -

    - {isInPostView && link ? ( +

    + {isInPostPageView && link ? ( {postTitle ?? '-'} @@ -219,7 +219,7 @@ const Post = ({ index, post = {} }: PostProps) => { )}

    - {!isInPostView && (!(commentMediaInfo?.type === 'webpage') || (commentMediaInfo?.type === 'webpage' && content?.trim().length > 0)) && ( + {!isInPostPageView && (!(commentMediaInfo?.type === 'webpage') || (commentMediaInfo?.type === 'webpage' && content?.trim().length > 0)) && ( { )}
    {t('submitted')} {getFormattedTimeAgo(timestamp)}{' '} - {edit && isInPostView && {t('last_edited', { timestamp: getFormattedTimeAgo(edit.timestamp) })}} {t('post_by')} + {edit && isInPostPageView && {t('last_edited', { timestamp: getFormattedTimeAgo(edit.timestamp) })}}{' '} + {t('post_by')} { - if (blocked || (isInPostView && (deleted || removed) && childrenCount === 0)) { + if (blocked || (isInPostPageView && (deleted || removed) && childrenCount === 0)) { setCollapsed(true); } - }, [blocked, isInPostView, deleted, removed, childrenCount]); + }, [blocked, isInPostPageView, deleted, removed, childrenCount]); const handleCollapseButton = () => { if (blocked) { unblock(); diff --git a/src/components/sidebar/sidebar.tsx b/src/components/sidebar/sidebar.tsx index 51fde8fa..1eedff8f 100644 --- a/src/components/sidebar/sidebar.tsx +++ b/src/components/sidebar/sidebar.tsx @@ -12,8 +12,8 @@ import { isAllView, isHomeAboutView, isHomeView, - isPendingView, - isPostView, + isPendingPostView, + isPostPageView, isSubplebbitAboutView, isSubplebbitSettingsView, isSubplebbitsView, @@ -219,8 +219,8 @@ const Sidebar = ({ comment, isSubCreatedButNotYetPublished, settings, subplebbit const isInAllView = isAllView(location.pathname); const isInHomeAboutView = isHomeAboutView(location.pathname); const isInHomeView = isHomeView(location.pathname); - const isInPendingView = isPendingView(location.pathname, params); - const isInPostView = isPostView(location.pathname, params); + const isInPendingPostView = isPendingPostView(location.pathname, params); + const isInPostPageView = isPostPageView(location.pathname, params); const isInSubplebbitsView = isSubplebbitsView(location.pathname); const isInSubplebbitAboutView = isSubplebbitAboutView(location.pathname, params); @@ -229,7 +229,7 @@ const Sidebar = ({ comment, isSubCreatedButNotYetPublished, settings, subplebbit const subplebbitCreator = findSubplebbitCreator(roles); const creatorAddress = subplebbitCreator === 'anonymous' ? 'anonymous' : `${Plebbit.getShortAddress(subplebbitCreator)}`; const submitRoute = - isInHomeView || isInHomeAboutView || isInAllView ? '/submit' : isInPendingView ? `/p/${pendingPost?.subplebbitAddress}/submit` : `/p/${address}/submit`; + isInHomeView || isInHomeAboutView || isInAllView ? '/submit' : isInPendingPostView ? `/p/${pendingPost?.subplebbitAddress}/submit` : `/p/${address}/submit`; const { blocked, unblock, block } = useBlock({ address }); @@ -271,7 +271,7 @@ const Sidebar = ({ comment, isSubCreatedButNotYetPublished, settings, subplebbit return (
    - {isInPostView && } + {isInPostPageView && } {/* TODO: add .largeButtonDisabled and disabledButtonDescription classnames for subs that don't accept posts */}
    @@ -279,7 +279,7 @@ const Sidebar = ({ comment, isSubCreatedButNotYetPublished, settings, subplebbit
    - {!isInHomeView && !isInHomeAboutView && !isInAllView && !isInPendingView && !isInSubplebbitsView && !isInHomeAboutView && ( + {!isInHomeView && !isInHomeAboutView && !isInAllView && !isInPendingPostView && !isInSubplebbitsView && !isInHomeAboutView && (
    {subplebbit?.address} diff --git a/src/hooks/use-comment-media-info.ts b/src/hooks/use-comment-media-info.ts index db4f60dd..1d2600c0 100644 --- a/src/hooks/use-comment-media-info.ts +++ b/src/hooks/use-comment-media-info.ts @@ -2,25 +2,25 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; import { useLocation, useParams } from 'react-router-dom'; import { Comment } from '@plebbit/plebbit-react-hooks'; import { getCommentMediaInfo, fetchWebpageThumbnailIfNeeded } from '../lib/utils/media-utils'; -import { isPendingView, isPostView } from '../lib/utils/view-utils'; +import { isPendingPostView, isPostPageView } from '../lib/utils/view-utils'; export const useCommentMediaInfo = (comment: Comment) => { const location = useLocation(); const params = useParams(); - const isInPostView = isPostView(location.pathname, params); - const isInPendingView = isPendingView(location.pathname, params); + const isInPostPageView = isPostPageView(location.pathname, params); + const isInPendingPostView = isPendingPostView(location.pathname, params); // some sites have CORS access, so the thumbnail can be fetched client-side, which is helpful if subplebbit.settings.fetchThumbnailUrls is false const initialCommentMediaInfo = useMemo(() => getCommentMediaInfo(comment), [comment]); const [commentMediaInfo, setCommentMediaInfo] = useState(initialCommentMediaInfo); const fetchThumbnail = useCallback(async () => { - if (!isInPostView && !isInPendingView) { + if (!isInPostPageView && !isInPendingPostView) { return; // don't fetch in feed view, it displaces the posts } if (initialCommentMediaInfo?.type === 'webpage' && !initialCommentMediaInfo.thumbnail) { const newMediaInfo = await fetchWebpageThumbnailIfNeeded(initialCommentMediaInfo); setCommentMediaInfo(newMediaInfo); } - }, [initialCommentMediaInfo, isInPostView, isInPendingView]); + }, [initialCommentMediaInfo, isInPostPageView, isInPendingPostView]); useEffect(() => { fetchThumbnail(); }, [fetchThumbnail]); diff --git a/src/lib/utils/view-utils.ts b/src/lib/utils/view-utils.ts index 07073e54..898e0605 100644 --- a/src/lib/utils/view-utils.ts +++ b/src/lib/utils/view-utils.ts @@ -85,11 +85,11 @@ export const isInboxUnreadView = (pathname: string): boolean => { return pathname === `/inbox/unread`; }; -export const isPendingView = (pathname: string, params: ParamsType): boolean => { +export const isPendingPostView = (pathname: string, params: ParamsType): boolean => { return pathname === `/profile/${params.accountCommentIndex}`; }; -export const isPostView = (pathname: string, params: ParamsType): boolean => { +export const isPostPageView = (pathname: string, params: ParamsType): boolean => { // some subs might use emojis in their address, so we need to decode the pathname const decodedPathname = decodeURIComponent(pathname); return params.subplebbitAddress && params.commentCid ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/c/${params.commentCid}`) : false; diff --git a/src/views/post-page/post-page.tsx b/src/views/post-page/post-page.tsx index 98e38245..f8377629 100644 --- a/src/views/post-page/post-page.tsx +++ b/src/views/post-page/post-page.tsx @@ -10,7 +10,7 @@ import PostComponent from '../../components/post'; import Sidebar from '../../components/sidebar'; import useReplies from '../../hooks/use-replies'; import useStateString from '../../hooks/use-state-string'; -import { isPendingView, isPostContextView } from '../../lib/utils/view-utils'; +import { isPendingPostView, isPostContextView } from '../../lib/utils/view-utils'; import findTopParentCidOfReply from '../../lib/utils/cid-utils'; import _ from 'lodash'; @@ -148,7 +148,7 @@ const PostWithContext = ({ post }: { post: Comment }) => { const PostPage = () => { const params = useParams(); const location = useLocation(); - const isInPendingView = isPendingView(location.pathname, params); + const isInPendingPostView = isPendingPostView(location.pathname, params); const isInPostContextView = isPostContextView(location.pathname, params, location.search); const post = useComment({ commentCid: params?.commentCid }); @@ -169,7 +169,7 @@ const PostPage = () => {
    - {isInPendingView && params?.accountCommentIndex ? ( + {isInPendingPostView && params?.accountCommentIndex ? ( ) : isInPostContextView ? (