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

37 lines
1.5 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;
};
export const isHomeView = (pathname: string): boolean => {
return pathname === '/';
};
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;
};
export const isRulesView = (pathname: string, params: ParamsType): boolean => {
const decodedPathname = decodeURIComponent(pathname);
return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/rules`) : false;
};
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
export const isCatalogView = (pathname: string, params: ParamsType): boolean => {
const decodedPathname = decodeURIComponent(pathname);
return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/catalog`) : false;
};
2024-04-25 22:02:55 +02:00
export const isPendingPostView = (pathname: string, params: ParamsType): boolean => {
return pathname === `/profile/${params.accountCommentIndex}`;
};