feat(use-current-view): add isPendingView

This commit is contained in:
plebeius.eth
2023-11-06 12:21:09 +01:00
parent dc989a9f7e
commit 3e33f501c9

View File

@@ -2,31 +2,34 @@ import { useLocation, useParams } from 'react-router-dom';
type CurrentView = {
isHomeView: boolean;
isSubplebbitView: boolean;
isPendingView: boolean;
isPostView: boolean;
isSubmitView: boolean;
isSubplebbitView: boolean;
isSubplebbitSubmitView: boolean;
};
type ParamsType = {
subplebbitAddress?: string;
accountCommentIndex?: string;
commentCid?: string;
subplebbitAddress?: string;
};
const sortTypes = ['/hot', '/new', '/active', '/controversialAll', '/topAll'];
const useCurrentView = (): CurrentView => {
const location = useLocation();
const { subplebbitAddress, commentCid } = useParams<ParamsType>();
const { accountCommentIndex, commentCid, subplebbitAddress } = useParams<ParamsType>();
const pathname = location.pathname;
const isHomeView = pathname === `/` || sortTypes.includes(pathname);
const isSubplebbitView = subplebbitAddress ? pathname.startsWith(`/p/${subplebbitAddress}`) : false;
const isPendingView = pathname === `/profile/${accountCommentIndex}`;
const isPostView = subplebbitAddress && commentCid ? pathname.startsWith(`/p/${subplebbitAddress}/c/${commentCid}`) : false;
const isSubmitView = pathname === `/submit`;
const isSubplebbitView = subplebbitAddress ? pathname.startsWith(`/p/${subplebbitAddress}`) : false;
const isSubplebbitSubmitView = subplebbitAddress ? pathname === `/p/${subplebbitAddress}/submit` : false;
return { isHomeView, isSubplebbitView, isPostView, isSubmitView, isSubplebbitSubmitView };
return { isHomeView, isSubplebbitView, isPendingView, isPostView, isSubmitView, isSubplebbitSubmitView };
};
export default useCurrentView;