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-06-09 16:40:32 +02:00
|
|
|
timeFilterName?: string;
|
2024-04-03 22:52:27 +02:00
|
|
|
};
|
|
|
|
|
|
2024-10-29 17:40:09 +01:00
|
|
|
export const isAllView = (pathname: string): boolean => {
|
|
|
|
|
return pathname.startsWith('/p/all');
|
2024-05-17 14:54:41 +02:00
|
|
|
};
|
|
|
|
|
|
2024-05-30 14:29:02 +02:00
|
|
|
export const isBoardView = (pathname: string, params: ParamsType): boolean => {
|
|
|
|
|
// some subs might use emojis in their address, so we need to decode the pathname
|
|
|
|
|
const decodedPathname = decodeURIComponent(pathname);
|
|
|
|
|
return params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}`) : false;
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-09 16:40:32 +02:00
|
|
|
export const isCatalogView = (pathname: string, params: ParamsType): boolean => {
|
|
|
|
|
const { subplebbitAddress, timeFilterName } = params;
|
|
|
|
|
const decodedPathname = decodeURIComponent(pathname);
|
|
|
|
|
|
|
|
|
|
return (
|
2024-06-11 15:13:04 +02:00
|
|
|
decodedPathname === `/p/${subplebbitAddress}/catalog` ||
|
2024-06-11 12:04:16 +02:00
|
|
|
decodedPathname === `/p/${subplebbitAddress}/catalog/settings` ||
|
2024-06-09 16:40:32 +02:00
|
|
|
decodedPathname === `/p/all/catalog` ||
|
2024-06-11 15:13:04 +02:00
|
|
|
decodedPathname === `/p/all/catalog/settings` ||
|
2024-06-09 16:40:32 +02:00
|
|
|
decodedPathname === `/p/all/catalog/${timeFilterName}` ||
|
2024-07-02 19:23:39 +02:00
|
|
|
decodedPathname === `/p/all/catalog/${timeFilterName}/settings` ||
|
2024-06-09 16:40:32 +02:00
|
|
|
decodedPathname === `/p/subscriptions/catalog` ||
|
2024-06-11 15:13:04 +02:00
|
|
|
decodedPathname === `/p/subscriptions/catalog/settings` ||
|
2024-07-02 19:23:39 +02:00
|
|
|
decodedPathname === `/p/subscriptions/catalog/${timeFilterName}` ||
|
|
|
|
|
decodedPathname === `/p/subscriptions/catalog/${timeFilterName}/settings`
|
2024-06-09 16:40:32 +02:00
|
|
|
);
|
2024-03-17 16:27:15 +01:00
|
|
|
};
|
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);
|
2024-05-17 17:25:25 +02:00
|
|
|
return pathname === '/p/all/description' ? true : params.subplebbitAddress ? decodedPathname.startsWith(`/p/${params.subplebbitAddress}/description`) : false;
|
2024-04-08 17:32:12 +02:00
|
|
|
};
|
|
|
|
|
|
2024-05-17 14:54:41 +02:00
|
|
|
export const isHomeView = (pathname: string): boolean => {
|
|
|
|
|
return pathname === '/';
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-05 17:38:34 +01:00
|
|
|
export const isModView = (pathname: string): boolean => {
|
|
|
|
|
return pathname === `/p/mod` || pathname.startsWith(`/p/mod/`);
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-17 14:54:41 +02:00
|
|
|
export const isPendingPostView = (pathname: string, params: ParamsType): boolean => {
|
2024-08-06 22:03:19 +02:00
|
|
|
return pathname === `/profile/${params.accountCommentIndex}` || pathname === `/profile/${params.accountCommentIndex}/settings`;
|
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-31 19:59:08 +02:00
|
|
|
export const isSettingsView = (pathname: string, params: ParamsType): boolean => {
|
2024-06-08 14:35:24 +02:00
|
|
|
const { accountCommentIndex, commentCid, subplebbitAddress } = params;
|
2024-05-31 19:59:08 +02:00
|
|
|
const decodedPathname = decodeURIComponent(pathname);
|
|
|
|
|
return (
|
|
|
|
|
decodedPathname === `/p/${subplebbitAddress}/c/${commentCid}/settings` ||
|
|
|
|
|
decodedPathname === `/p/${subplebbitAddress}/description/settings` ||
|
2024-06-08 14:35:24 +02:00
|
|
|
decodedPathname === `/p/${subplebbitAddress}/rules/settings` ||
|
|
|
|
|
decodedPathname === `/profile/${accountCommentIndex}/settings`
|
2024-05-31 19:59:08 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-17 12:17:36 +02:00
|
|
|
export const isSubscriptionsView = (pathname: string, params: ParamsType): boolean => {
|
|
|
|
|
const { timeFilterName } = params;
|
|
|
|
|
return (
|
|
|
|
|
pathname === '/p/subscriptions' ||
|
|
|
|
|
pathname === '/p/subscriptions/settings' ||
|
|
|
|
|
pathname === `/p/subscriptions/${timeFilterName}` ||
|
|
|
|
|
pathname === `/p/subscriptions/${timeFilterName}/settings` ||
|
|
|
|
|
pathname === '/p/subscriptions/catalog' ||
|
|
|
|
|
pathname === '/p/subscriptions/catalog/settings' ||
|
|
|
|
|
pathname === `/p/subscriptions/catalog/${timeFilterName}` ||
|
|
|
|
|
pathname === `/p/subscriptions/catalog/${timeFilterName}/settings`
|
|
|
|
|
);
|
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 (
|
2024-10-29 17:40:09 +01:00
|
|
|
!isAllView(pathname) &&
|
2024-05-30 14:29:02 +02:00
|
|
|
!isBoardView(pathname, params) &&
|
2024-06-09 16:40:32 +02:00
|
|
|
!isCatalogView(pathname, params) &&
|
2024-05-17 14:54:41 +02:00
|
|
|
!isDescriptionView(pathname, params) &&
|
|
|
|
|
!isHomeView(pathname) &&
|
|
|
|
|
!isPendingPostView(pathname, params) &&
|
|
|
|
|
!isPostPageView(pathname, params) &&
|
2024-06-17 12:17:36 +02:00
|
|
|
!isRulesView(pathname, params) &&
|
|
|
|
|
!isSettingsView(pathname, params) &&
|
|
|
|
|
!isSubscriptionsView(pathname, params)
|
2024-05-06 21:40:17 +02:00
|
|
|
);
|
|
|
|
|
};
|