feat(board): add p/all and p/subscriptions

This commit is contained in:
plebeius.eth
2024-05-17 14:54:41 +02:00
parent 50df786a86
commit 86223bb249
4 changed files with 72 additions and 28 deletions
+7 -1
View File
@@ -37,7 +37,7 @@ const BoardLayout = () => {
<BoardBanner /> <BoardBanner />
<MobileBoardButtons /> <MobileBoardButtons />
<PostForm key={key} /> <PostForm key={key} />
<SubplebbitStats /> {subplebbitAddress && isValidSubplebbitAddress && <SubplebbitStats />}
<DesktopBoardButtons /> <DesktopBoardButtons />
<Outlet /> <Outlet />
</div> </div>
@@ -71,6 +71,12 @@ const App = () => {
<Route path='/p/:subplebbitAddress' element={<Board />} /> <Route path='/p/:subplebbitAddress' element={<Board />} />
<Route path='/p/:subplebbitAddress/settings' element={<Board />} /> <Route path='/p/:subplebbitAddress/settings' element={<Board />} />
<Route path='/p/subscriptions' element={<Board />} />
<Route path='/p/subscriptions/settings' element={<Board />} />
<Route path='/p/all' element={<Board />} />
<Route path='/p/all/settings' element={<Board />} />
<Route path='/p/:subplebbitAddress/catalog' element={<Catalog />} /> <Route path='/p/:subplebbitAddress/catalog' element={<Catalog />} />
<Route path='/p/:subplebbitAddress/catalog/settings' element={<Catalog />} /> <Route path='/p/:subplebbitAddress/catalog/settings' element={<Catalog />} />
+22 -14
View File
@@ -4,8 +4,13 @@ export type ParamsType = {
subplebbitAddress?: string; subplebbitAddress?: string;
}; };
export const isHomeView = (pathname: string): boolean => { export const isAllView = (pathname: string): boolean => {
return pathname === '/'; return pathname === '/p/all';
};
export const isCatalogView = (pathname: string, params: ParamsType): boolean => {
const decodedPathname = decodeURIComponent(pathname);
return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/catalog`) : false;
}; };
export const isDescriptionView = (pathname: string, params: ParamsType): boolean => { export const isDescriptionView = (pathname: string, params: ParamsType): boolean => {
@@ -13,9 +18,12 @@ export const isDescriptionView = (pathname: string, params: ParamsType): boolean
return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/description`) : false; return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/description`) : false;
}; };
export const isRulesView = (pathname: string, params: ParamsType): boolean => { export const isHomeView = (pathname: string): boolean => {
const decodedPathname = decodeURIComponent(pathname); return pathname === '/';
return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/rules`) : false; };
export const isPendingPostView = (pathname: string, params: ParamsType): boolean => {
return pathname === `/profile/${params.accountCommentIndex}`;
}; };
export const isPostPageView = (pathname: string, params: ParamsType): boolean => { export const isPostPageView = (pathname: string, params: ParamsType): boolean => {
@@ -26,22 +34,22 @@ export const isPostPageView = (pathname: string, params: ParamsType): boolean =>
return params.subplebbitAddress && params.commentCid ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/c/${params.commentCid}`) : false; return params.subplebbitAddress && params.commentCid ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/c/${params.commentCid}`) : false;
}; };
export const isCatalogView = (pathname: string, params: ParamsType): boolean => { export const isRulesView = (pathname: string, params: ParamsType): boolean => {
const decodedPathname = decodeURIComponent(pathname); const decodedPathname = decodeURIComponent(pathname);
return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/catalog`) : false; return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/rules`) : false;
}; };
export const isPendingPostView = (pathname: string, params: ParamsType): boolean => { export const isSubscriptionsView = (pathname: string): boolean => {
return pathname === `/profile/${params.accountCommentIndex}`; return pathname === '/p/subscriptions';
}; };
export const isNotFoundView = (pathname: string, params: ParamsType): boolean => { export const isNotFoundView = (pathname: string, params: ParamsType): boolean => {
return ( return (
!isHomeView(pathname) &&
!isDescriptionView(pathname, params) &&
!isRulesView(pathname, params) &&
!isPostPageView(pathname, params) &&
!isCatalogView(pathname, params) && !isCatalogView(pathname, params) &&
!isPendingPostView(pathname, params) !isDescriptionView(pathname, params) &&
!isHomeView(pathname) &&
!isPendingPostView(pathname, params) &&
!isPostPageView(pathname, params) &&
!isRulesView(pathname, params)
); );
}; };
+34 -13
View File
@@ -1,9 +1,11 @@
import { useEffect, useMemo, useRef } from 'react'; import { useEffect, useMemo, useRef } from 'react';
import { useLocation, useParams } from 'react-router-dom'; import { useLocation, useParams } from 'react-router-dom';
import { useFeed, useSubplebbit } from '@plebbit/plebbit-react-hooks'; import { useAccount, useFeed, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import { Virtuoso, VirtuosoHandle, StateSnapshot } from 'react-virtuoso'; import { Virtuoso, VirtuosoHandle, StateSnapshot } from 'react-virtuoso';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import styles from './board.module.css'; import styles from './board.module.css';
import { isAllView, isSubscriptionsView } from '../../lib/utils/view-utils';
import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits';
import useFeedStateString from '../../hooks/use-feed-state-string'; import useFeedStateString from '../../hooks/use-feed-state-string';
import useReplyModal from '../../hooks/use-reply-modal'; import useReplyModal from '../../hooks/use-reply-modal';
import LoadingEllipsis from '../../components/loading-ellipsis'; import LoadingEllipsis from '../../components/loading-ellipsis';
@@ -19,12 +21,30 @@ const Board = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const location = useLocation(); const location = useLocation();
const { subplebbitAddress } = useParams<{ subplebbitAddress: string }>(); const { subplebbitAddress } = useParams<{ subplebbitAddress: string }>();
const subplebbitAddresses = useMemo(() => [subplebbitAddress], [subplebbitAddress]) as string[];
const isInAllView = isAllView(location.pathname);
const defaultSubplebbitAddresses = useDefaultSubplebbitAddresses();
const account = useAccount();
const subscriptions = account?.subscriptions;
const isInSubscriptionsView = isSubscriptionsView(location.pathname);
const subplebbitAddresses = useMemo(() => {
if (isInAllView) {
return defaultSubplebbitAddresses;
}
if (isInSubscriptionsView) {
return subscriptions || [];
}
return [subplebbitAddress];
}, [isInAllView, isInSubscriptionsView, subplebbitAddress, defaultSubplebbitAddresses, subscriptions]);
const sortType = 'active'; const sortType = 'active';
const { feed, hasMore, loadMore } = useFeed({ subplebbitAddresses, sortType }); const { feed, hasMore, loadMore } = useFeed({ subplebbitAddresses, sortType });
const subplebbit = useSubplebbit({ subplebbitAddress }); const subplebbit = useSubplebbit({ subplebbitAddress });
const { createdAt, description, rules, shortAddress, state, suggested, title } = subplebbit || {}; const { createdAt, description, rules, shortAddress, state, suggested } = subplebbit || {};
const title = isInAllView ? t('all') : isInSubscriptionsView ? t('subscriptions') : subplebbit?.title;
const { activeCid, closeModal, openReplyModal, showReplyModal, scrollY } = useReplyModal(); const { activeCid, closeModal, openReplyModal, showReplyModal, scrollY } = useReplyModal();
@@ -69,16 +89,17 @@ const Board = () => {
{feed.length > 0 && ( {feed.length > 0 && (
<> <>
{rules && rules.length > 0 && <SubplebbitRules subplebbitAddress={subplebbitAddress} createdAt={createdAt} rules={rules} />} {rules && rules.length > 0 && <SubplebbitRules subplebbitAddress={subplebbitAddress} createdAt={createdAt} rules={rules} />}
{description && description.length > 0 && ( {(description && description.length > 0) ||
<SubplebbitDescription (isInAllView && (
avatarUrl={suggested?.avatarUrl} <SubplebbitDescription
subplebbitAddress={subplebbitAddress} avatarUrl={suggested?.avatarUrl}
createdAt={createdAt} subplebbitAddress={subplebbitAddress}
description={description} createdAt={createdAt}
shortAddress={shortAddress} description={description}
title={title} shortAddress={shortAddress}
/> title={title}
)} />
))}
</> </>
)} )}
<Virtuoso <Virtuoso
+9
View File
@@ -115,6 +115,15 @@ const Boards = ({ multisub, subplebbits }: { multisub: Subplebbit[]; subplebbits
</div> </div>
<div className={styles.boardsBoxContent}> <div className={styles.boardsBoxContent}>
<div className={styles.column}> <div className={styles.column}>
<h3>Multiboards</h3>
<div className={styles.list}>
<div className={styles.subplebbit}>
<Link to='/p/all'>All</Link>
</div>
<div className={styles.subplebbit}>
<Link to='/p/subscriptions'>Subscriptions</Link>
</div>
</div>
<h3>Plebbit</h3> <h3>Plebbit</h3>
<div className={styles.list}> <div className={styles.list}>
{plebbitSubs.map((sub) => ( {plebbitSubs.map((sub) => (