feat(subplebbit): add automatic theme based on nsfw or sfw tags

This commit is contained in:
Tom (plebeius.eth)
2024-06-17 12:17:36 +02:00
parent 77ccf0c849
commit 22c1acdd3d
20 changed files with 189 additions and 87 deletions
+37 -6
View File
@@ -1,3 +1,5 @@
import { timeFilterNames } from '../../hooks/use-time-filter';
export type ParamsType = {
accountCommentIndex?: string;
commentCid?: string;
@@ -5,8 +7,25 @@ export type ParamsType = {
timeFilterName?: string;
};
export const isAllView = (pathname: string): boolean => {
return pathname.startsWith('/p/all');
export const isAllView = (pathname: string, params: ParamsType): boolean => {
const { timeFilterName } = params;
if (timeFilterName && !timeFilterNames.includes(timeFilterName)) {
return false;
}
return (
pathname === '/p/all' ||
pathname === '/p/all/settings' ||
pathname === `/p/all/${timeFilterName}` ||
pathname === `/p/all/${timeFilterName}/settings` ||
pathname === '/p/all/catalog' ||
pathname === '/p/all/catalog/settings' ||
pathname === `/p/all/catalog/${timeFilterName}` ||
pathname === `/p/all/catalog/${timeFilterName}/settings` ||
pathname === '/p/all/description' ||
pathname === '/p/all/description/settings'
);
};
export const isBoardView = (pathname: string, params: ParamsType): boolean => {
@@ -68,19 +87,31 @@ export const isSettingsView = (pathname: string, params: ParamsType): boolean =>
);
};
export const isSubscriptionsView = (pathname: string): boolean => {
return pathname.startsWith('/p/subscriptions');
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`
);
};
export const isNotFoundView = (pathname: string, params: ParamsType): boolean => {
return (
!isAllView(pathname) &&
!isAllView(pathname, params) &&
!isBoardView(pathname, params) &&
!isCatalogView(pathname, params) &&
!isDescriptionView(pathname, params) &&
!isHomeView(pathname) &&
!isPendingPostView(pathname, params) &&
!isPostPageView(pathname, params) &&
!isRulesView(pathname, params)
!isRulesView(pathname, params) &&
!isSettingsView(pathname, params) &&
!isSubscriptionsView(pathname, params)
);
};