mirror of
https://github.com/plebbit/seedit.git
synced 2026-02-06 12:01:04 -05:00
rename variables
This commit is contained in:
@@ -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 (
|
||||
<li className={isInPostView && !isInHomeAboutView ? styles.selected : styles.choice}>
|
||||
<li className={isInPostPageView && !isInHomeAboutView ? styles.selected : styles.choice}>
|
||||
<Link to={`/p/${params.subplebbitAddress}/c/${params.commentCid}`}>{t('comments')}</Link>
|
||||
</li>
|
||||
);
|
||||
@@ -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 <CommentsButton />;
|
||||
} else if (isInHomeView || isInHomeAboutView || (isInSubplebbitView && !isInSubplebbitSubmitView && !isInSubplebbitSettingsView) || isInAllView) {
|
||||
return <SortItems />;
|
||||
} else if ((isInProfileView || isInAuthorView) && !isInPendingView) {
|
||||
} else if ((isInProfileView || isInAuthorView) && !isInPendingPostView) {
|
||||
return <AuthorHeaderTabs />;
|
||||
} else if (isInPendingView) {
|
||||
} else if (isInPendingPostView) {
|
||||
return <span className={styles.pageName}>{t('pending')}</span>;
|
||||
} else if (isInInboxView) {
|
||||
return <InboxHeaderTabs />;
|
||||
@@ -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 && (
|
||||
<ul className={`${styles.tabMenu} ${isInProfileView ? styles.horizontalScroll : ''}`}>
|
||||
<HeaderTabs />
|
||||
{(isInHomeView || isInHomeAboutView || isInSubplebbitView || isInHomeAboutView || isInAllView || isInPostView) && <AboutButton />}
|
||||
{(isInHomeView || isInHomeAboutView || isInSubplebbitView || isInHomeAboutView || isInAllView || isInPostPageView) && <AboutButton />}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -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) => {
|
||||
<div className={`${styles.arrowCommon} ${downvoted ? styles.downvoted : styles.arrowDown}`} onClick={() => cid && downvote()} />
|
||||
</div>
|
||||
</div>
|
||||
{hasThumbnail && (!isInPostView || commentMediaInfo?.type === 'webpage') && !spoiler && (
|
||||
{hasThumbnail && (!isInPostPageView || commentMediaInfo?.type === 'webpage') && !spoiler && (
|
||||
<span className={removed ? styles.blur : ''}>
|
||||
<Thumbnail
|
||||
cid={cid}
|
||||
@@ -193,8 +193,8 @@ const Post = ({ index, post = {} }: PostProps) => {
|
||||
</div>
|
||||
<div className={styles.entry}>
|
||||
<div className={styles.topMatter}>
|
||||
<p className={`${styles.title} ${removed && !isInPostView ? styles.blur : ''}`}>
|
||||
{isInPostView && link ? (
|
||||
<p className={`${styles.title} ${removed && !isInPostPageView ? styles.blur : ''}`}>
|
||||
{isInPostPageView && link ? (
|
||||
<a href={link} className={linkClass} target='_blank' rel='noopener noreferrer' onClick={handlePostClick}>
|
||||
{postTitle ?? '-'}
|
||||
</a>
|
||||
@@ -219,7 +219,7 @@ const Post = ({ index, post = {} }: PostProps) => {
|
||||
</span>
|
||||
)}
|
||||
</p>
|
||||
{!isInPostView && (!(commentMediaInfo?.type === 'webpage') || (commentMediaInfo?.type === 'webpage' && content?.trim().length > 0)) && (
|
||||
{!isInPostPageView && (!(commentMediaInfo?.type === 'webpage') || (commentMediaInfo?.type === 'webpage' && content?.trim().length > 0)) && (
|
||||
<ExpandButton
|
||||
commentMediaInfo={commentMediaInfo}
|
||||
content={content}
|
||||
@@ -231,7 +231,8 @@ const Post = ({ index, post = {} }: PostProps) => {
|
||||
)}
|
||||
<div className={styles.tagline}>
|
||||
{t('submitted')} <span title={postDate}>{getFormattedTimeAgo(timestamp)}</span>{' '}
|
||||
{edit && isInPostView && <span className={styles.timeEdit}>{t('last_edited', { timestamp: getFormattedTimeAgo(edit.timestamp) })}</span>} {t('post_by')}
|
||||
{edit && isInPostPageView && <span className={styles.timeEdit}>{t('last_edited', { timestamp: getFormattedTimeAgo(edit.timestamp) })}</span>}{' '}
|
||||
{t('post_by')}
|
||||
<PostAuthor
|
||||
authorAddress={author?.address}
|
||||
authorRole={authorRole}
|
||||
|
||||
@@ -20,7 +20,7 @@ import ReplyForm from '../reply-form';
|
||||
import useDownvote from '../../hooks/use-downvote';
|
||||
import useStateString from '../../hooks/use-state-string';
|
||||
import useUpvote from '../../hooks/use-upvote';
|
||||
import { isInboxView, isPostContextView, isPostView } from '../../lib/utils/view-utils';
|
||||
import { isInboxView, isPostContextView, isPostPageView } from '../../lib/utils/view-utils';
|
||||
import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js';
|
||||
import Markdown from '../markdown';
|
||||
import { getHostname } from '../../lib/utils/url-utils';
|
||||
@@ -283,7 +283,7 @@ const Reply = ({ cidOfReplyWithContext, depth = 0, isSingleComment, isSingleRepl
|
||||
const params = useParams();
|
||||
const isInInboxView = isInboxView(location.pathname);
|
||||
const isInPostContextView = isPostContextView(location.pathname, params, location.search);
|
||||
const isInPostView = isPostView(location.pathname, params);
|
||||
const isInPostPageView = isPostPageView(location.pathname, params);
|
||||
|
||||
const authorRole = subplebbit?.roles?.[author?.address]?.role;
|
||||
const { shortAuthorAddress } = useAuthorAddress({ comment: reply });
|
||||
@@ -324,10 +324,10 @@ const Reply = ({ cidOfReplyWithContext, depth = 0, isSingleComment, isSingleRepl
|
||||
const { blocked, unblock } = useBlock({ cid });
|
||||
const [collapsed, setCollapsed] = useState(blocked);
|
||||
useEffect(() => {
|
||||
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();
|
||||
|
||||
@@ -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 (
|
||||
<div className={`${isMobile ? styles.mobileSidebar : styles.sidebar}`}>
|
||||
<SearchBar />
|
||||
{isInPostView && <PostInfo comment={comment} />}
|
||||
{isInPostPageView && <PostInfo comment={comment} />}
|
||||
<Link to={submitRoute}>
|
||||
{/* TODO: add .largeButtonDisabled and disabledButtonDescription classnames for subs that don't accept posts */}
|
||||
<div className={styles.largeButton}>
|
||||
@@ -279,7 +279,7 @@ const Sidebar = ({ comment, isSubCreatedButNotYetPublished, settings, subplebbit
|
||||
<div className={styles.nub} />
|
||||
</div>
|
||||
</Link>
|
||||
{!isInHomeView && !isInHomeAboutView && !isInAllView && !isInPendingView && !isInSubplebbitsView && !isInHomeAboutView && (
|
||||
{!isInHomeView && !isInHomeAboutView && !isInAllView && !isInPendingPostView && !isInSubplebbitsView && !isInHomeAboutView && (
|
||||
<div className={styles.titleBox}>
|
||||
<Link className={styles.title} to={`/p/${address}`}>
|
||||
{subplebbit?.address}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = () => {
|
||||
<div className={styles.sidebar}>
|
||||
<Sidebar subplebbit={subplebbit} comment={post} />
|
||||
</div>
|
||||
{isInPendingView && params?.accountCommentIndex ? (
|
||||
{isInPendingPostView && params?.accountCommentIndex ? (
|
||||
<PendingPost commentIndex={+params?.accountCommentIndex || undefined} />
|
||||
) : isInPostContextView ? (
|
||||
<PostWithContext post={post} />
|
||||
|
||||
Reference in New Issue
Block a user