2026-03-13 16:06:36 +08:00
|
|
|
import { isArchiveRoute, isBoardModRoute, isModQueueRoute } from './route-utils';
|
2026-03-07 16:02:19 +08:00
|
|
|
|
2026-03-08 16:37:34 +08:00
|
|
|
type ParamsType = {
|
2024-04-25 22:02:55 +02:00
|
|
|
accountCommentIndex?: string;
|
2025-11-07 12:50:58 +01:00
|
|
|
boardIdentifier?: string;
|
2024-04-03 22:52:27 +02:00
|
|
|
commentCid?: string;
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-29 17:40:09 +01:00
|
|
|
export const isAllView = (pathname: string): boolean => {
|
2025-11-07 12:50:58 +01:00
|
|
|
return pathname.startsWith('/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);
|
2025-11-07 12:50:58 +01:00
|
|
|
// Check if it's a board view (not all, subscriptions, mod, pending, or special routes)
|
|
|
|
|
if (
|
|
|
|
|
pathname.startsWith('/all') ||
|
2025-11-12 16:35:38 +01:00
|
|
|
pathname.startsWith('/subs') ||
|
2025-11-07 12:50:58 +01:00
|
|
|
pathname.startsWith('/mod') ||
|
2026-03-13 16:06:36 +08:00
|
|
|
isArchiveRoute(pathname) ||
|
2026-03-07 16:02:19 +08:00
|
|
|
isBoardModRoute(pathname) ||
|
2025-11-07 12:50:58 +01:00
|
|
|
pathname.startsWith('/pending') ||
|
|
|
|
|
pathname === '/' ||
|
|
|
|
|
pathname.startsWith('/faq') ||
|
|
|
|
|
pathname.startsWith('/not-found')
|
|
|
|
|
) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-04-17 10:48:27 +07:00
|
|
|
const identifier = params.boardIdentifier;
|
2025-11-07 12:50:58 +01:00
|
|
|
return identifier ? decodedPathname.startsWith(`/${identifier}`) : false;
|
2024-05-30 14:29:02 +02:00
|
|
|
};
|
|
|
|
|
|
2024-06-09 16:40:32 +02:00
|
|
|
export const isCatalogView = (pathname: string, params: ParamsType): boolean => {
|
2026-04-17 10:48:27 +07:00
|
|
|
const { boardIdentifier } = params;
|
|
|
|
|
const identifier = boardIdentifier;
|
2024-06-09 16:40:32 +02:00
|
|
|
const decodedPathname = decodeURIComponent(pathname);
|
|
|
|
|
|
|
|
|
|
return (
|
2025-11-07 12:50:58 +01:00
|
|
|
(identifier && (decodedPathname === `/${identifier}/catalog` || decodedPathname === `/${identifier}/catalog/settings`)) ||
|
|
|
|
|
decodedPathname === `/all/catalog` ||
|
|
|
|
|
decodedPathname === `/all/catalog/settings` ||
|
2025-11-12 16:35:38 +01:00
|
|
|
decodedPathname === `/subs/catalog` ||
|
|
|
|
|
decodedPathname === `/subs/catalog/settings` ||
|
2025-11-07 12:50:58 +01:00
|
|
|
decodedPathname === `/mod/catalog` ||
|
2026-02-22 15:57:42 +08:00
|
|
|
decodedPathname === `/mod/catalog/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-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 => {
|
2025-11-07 12:50:58 +01:00
|
|
|
return pathname === `/mod` || pathname.startsWith(`/mod/`);
|
2025-03-05 17:38:34 +01:00
|
|
|
};
|
|
|
|
|
|
2026-01-07 16:03:02 +01:00
|
|
|
export const isModQueueView = (pathname: string): boolean => {
|
2026-03-07 16:02:19 +08:00
|
|
|
return isModQueueRoute(pathname);
|
2026-01-07 16:03:02 +01:00
|
|
|
};
|
|
|
|
|
|
2024-05-17 14:54:41 +02:00
|
|
|
export const isPendingPostView = (pathname: string, params: ParamsType): boolean => {
|
2025-11-07 12:50:58 +01:00
|
|
|
return pathname === `/pending/${params.accountCommentIndex}` || pathname === `/pending/${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 => {
|
|
|
|
|
const decodedPathname = decodeURIComponent(pathname);
|
2026-04-17 10:48:27 +07:00
|
|
|
const identifier = params.boardIdentifier;
|
2025-11-07 12:50:58 +01:00
|
|
|
return identifier && params.commentCid ? decodedPathname.startsWith(`/${identifier}/thread/${params.commentCid}`) : false;
|
2024-04-03 22:52:27 +02:00
|
|
|
};
|
2024-04-12 17:47:30 +02:00
|
|
|
|
2024-05-31 19:59:08 +02:00
|
|
|
export const isSettingsView = (pathname: string, params: ParamsType): boolean => {
|
2026-04-17 10:48:27 +07:00
|
|
|
const { accountCommentIndex, boardIdentifier, commentCid } = params;
|
|
|
|
|
const identifier = boardIdentifier;
|
2024-05-31 19:59:08 +02:00
|
|
|
const decodedPathname = decodeURIComponent(pathname);
|
|
|
|
|
return (
|
2025-12-23 19:14:25 +01:00
|
|
|
(identifier && commentCid && decodedPathname === `/${identifier}/thread/${commentCid}/settings`) || decodedPathname === `/pending/${accountCommentIndex}/settings`
|
2024-05-31 19:59:08 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-10 18:25:13 +07:00
|
|
|
export const isSubscriptionsView = (pathname: string, _params: ParamsType): boolean => {
|
2026-02-22 15:57:42 +08:00
|
|
|
return pathname === '/subs' || pathname === '/subs/settings' || pathname === '/subs/catalog' || pathname === '/subs/catalog/settings';
|
2024-04-25 22:02:55 +02:00
|
|
|
};
|
2024-05-06 21:40:17 +02:00
|
|
|
|
2026-03-13 16:06:36 +08:00
|
|
|
export const isArchiveView = (pathname: string, params: ParamsType): boolean => {
|
2026-04-17 10:48:27 +07:00
|
|
|
const { boardIdentifier } = params;
|
|
|
|
|
const identifier = boardIdentifier;
|
2026-03-13 16:06:36 +08:00
|
|
|
const decodedPathname = decodeURIComponent(pathname);
|
|
|
|
|
|
|
|
|
|
return Boolean(identifier && isArchiveRoute(decodedPathname) && decodedPathname === `/${identifier}/archive`);
|
|
|
|
|
};
|
|
|
|
|
|
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) &&
|
2026-03-13 16:06:36 +08:00
|
|
|
!isArchiveView(pathname, params) &&
|
2024-06-09 16:40:32 +02:00
|
|
|
!isCatalogView(pathname, params) &&
|
2024-05-17 14:54:41 +02:00
|
|
|
!isHomeView(pathname) &&
|
|
|
|
|
!isPendingPostView(pathname, params) &&
|
|
|
|
|
!isPostPageView(pathname, params) &&
|
2024-06-17 12:17:36 +02:00
|
|
|
!isSettingsView(pathname, params) &&
|
2026-01-07 16:03:02 +01:00
|
|
|
!isSubscriptionsView(pathname, params) &&
|
|
|
|
|
!isModQueueView(pathname)
|
2024-05-06 21:40:17 +02:00
|
|
|
);
|
|
|
|
|
};
|