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

107 lines
3.9 KiB
TypeScript
Raw Normal View History

import { isArchiveRoute, isBoardModRoute, isModQueueRoute } from './route-utils';
type ParamsType = {
2024-04-25 22:02:55 +02:00
accountCommentIndex?: string;
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 => {
return pathname.startsWith('/all');
2024-05-17 14:54:41 +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);
// Check if it's a board view (not all, subscriptions, mod, pending, or special routes)
if (
pathname.startsWith('/all') ||
pathname.startsWith('/subs') ||
pathname.startsWith('/mod') ||
isArchiveRoute(pathname) ||
isBoardModRoute(pathname) ||
pathname.startsWith('/pending') ||
pathname === '/' ||
pathname.startsWith('/faq') ||
pathname.startsWith('/not-found')
) {
return false;
}
const identifier = params.boardIdentifier;
return identifier ? decodedPathname.startsWith(`/${identifier}`) : false;
};
export const isCatalogView = (pathname: string, params: ParamsType): boolean => {
const { boardIdentifier } = params;
const identifier = boardIdentifier;
const decodedPathname = decodeURIComponent(pathname);
return (
(identifier && (decodedPathname === `/${identifier}/catalog` || decodedPathname === `/${identifier}/catalog/settings`)) ||
decodedPathname === `/all/catalog` ||
decodedPathname === `/all/catalog/settings` ||
decodedPathname === `/subs/catalog` ||
decodedPathname === `/subs/catalog/settings` ||
decodedPathname === `/mod/catalog` ||
decodedPathname === `/mod/catalog/settings`
);
};
2024-04-03 22:52:27 +02:00
2024-05-17 14:54:41 +02:00
export const isHomeView = (pathname: string): boolean => {
return pathname === '/';
};
export const isModView = (pathname: string): boolean => {
return pathname === `/mod` || pathname.startsWith(`/mod/`);
};
2026-01-07 16:03:02 +01:00
export const isModQueueView = (pathname: string): boolean => {
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 => {
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);
const identifier = params.boardIdentifier;
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
export const isSettingsView = (pathname: string, params: ParamsType): boolean => {
const { accountCommentIndex, boardIdentifier, commentCid } = params;
const identifier = boardIdentifier;
const decodedPathname = decodeURIComponent(pathname);
return (
(identifier && commentCid && decodedPathname === `/${identifier}/thread/${commentCid}/settings`) || decodedPathname === `/pending/${accountCommentIndex}/settings`
);
};
export const isSubscriptionsView = (pathname: string, _params: ParamsType): boolean => {
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
export const isArchiveView = (pathname: string, params: ParamsType): boolean => {
const { boardIdentifier } = params;
const identifier = boardIdentifier;
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) &&
!isBoardView(pathname, params) &&
!isArchiveView(pathname, params) &&
!isCatalogView(pathname, params) &&
2024-05-17 14:54:41 +02:00
!isHomeView(pathname) &&
!isPendingPostView(pathname, params) &&
!isPostPageView(pathname, params) &&
!isSettingsView(pathname, params) &&
2026-01-07 16:03:02 +01:00
!isSubscriptionsView(pathname, params) &&
!isModQueueView(pathname)
2024-05-06 21:40:17 +02:00
);
};