mirror of
https://github.com/plebbit/seedit.git
synced 2026-05-24 00:29:58 -04:00
feat(use-current-view): add isPendingView
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user