Files
5chan/src/lib/utils/view-utils.ts
T

56 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-04-03 22:52:27 +02:00
export type ParamsType = {
2024-04-25 22:02:55 +02:00
accountCommentIndex?: string;
2024-04-03 22:52:27 +02:00
commentCid?: string;
subplebbitAddress?: string;
};
2024-05-17 14:54:41 +02:00
export const isAllView = (pathname: string): boolean => {
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;
};
2024-04-03 22:52:27 +02:00
2024-04-08 17:32:12 +02:00
export const isDescriptionView = (pathname: string, params: ParamsType): boolean => {
const decodedPathname = decodeURIComponent(pathname);
return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/description`) : false;
};
2024-05-17 14:54:41 +02:00
export const isHomeView = (pathname: string): boolean => {
return pathname === '/';
};
export const isPendingPostView = (pathname: string, params: ParamsType): boolean => {
return pathname === `/profile/${params.accountCommentIndex}`;
2024-04-08 17:32:12 +02:00
};
2024-04-03 22:52:27 +02:00
export const isPostPageView = (pathname: string, params: ParamsType): boolean => {
2024-04-08 17:32:12 +02:00
if (isDescriptionView(pathname, params) || isRulesView(pathname, params)) {
return true;
}
2024-04-03 22:52:27 +02:00
const decodedPathname = decodeURIComponent(pathname);
return params.subplebbitAddress && params.commentCid ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/c/${params.commentCid}`) : false;
};
2024-04-12 17:47:30 +02:00
2024-05-17 14:54:41 +02:00
export const isRulesView = (pathname: string, params: ParamsType): boolean => {
2024-04-12 17:47:30 +02:00
const decodedPathname = decodeURIComponent(pathname);
2024-05-17 14:54:41 +02:00
return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/rules`) : false;
2024-04-12 17:47:30 +02:00
};
2024-04-25 22:02:55 +02:00
2024-05-17 14:54:41 +02:00
export const isSubscriptionsView = (pathname: string): boolean => {
return pathname === '/p/subscriptions';
2024-04-25 22:02:55 +02:00
};
2024-05-06 21:40:17 +02:00
export const isNotFoundView = (pathname: string, params: ParamsType): boolean => {
return (
!isCatalogView(pathname, params) &&
2024-05-17 14:54:41 +02:00
!isDescriptionView(pathname, params) &&
!isHomeView(pathname) &&
!isPendingPostView(pathname, params) &&
!isPostPageView(pathname, params) &&
!isRulesView(pathname, params)
2024-05-06 21:40:17 +02:00
);
};