Files
seedit/src/lib/utils/view-utils.ts
2023-12-09 18:01:08 +01:00

76 lines
2.7 KiB
TypeScript

import { timeFilterNames, TimeFilterKey } from "../../hooks/use-time-filter";
export type ParamsType = {
accountCommentIndex?: string;
authorAddress?: string;
commentCid?: string;
subplebbitAddress?: string;
timeFilterName?: string;
};
export type ViewType = 'home' | 'pending' | 'post' | 'submit' | 'subplebbit' | 'subplebbit/submit';
const sortTypes = ['/hot', '/new', '/active', '/controversialAll', '/topAll'];
export const getAboutLink = (pathname: string, params: ParamsType): string => {
if (pathname.startsWith(`/p/${params.subplebbitAddress}/c/${params.commentCid}`)) {
return `/p/${params.subplebbitAddress}/c/${params.commentCid}/about`;
} else if (pathname.startsWith(`/p/${params.subplebbitAddress}`)) {
return `/p/${params.subplebbitAddress}/about`;
} else if (pathname.startsWith('/profile')) {
return '/profile/about';
} else if (pathname.startsWith('/u/')) {
return `/u/${params.authorAddress}/c/${params.commentCid}/about`;
} else {
return '/about';
}
};
export const isAboutView = (pathname: string): boolean => {
return pathname.endsWith('/about');
}
export const isAllView = (pathname: string): boolean => {
return pathname.startsWith('/p/all');
}
export const isAuthorView = (pathname: string): boolean => {
return pathname.startsWith('/u/');
}
export const isHomeView = (pathname: string, params: ParamsType): boolean => {
return pathname === '/' || (sortTypes.includes(pathname) || (timeFilterNames.includes(params.timeFilterName as TimeFilterKey) && !pathname.startsWith('/p/all')));
};
export const isInboxView = (pathname: string): boolean => {
return pathname.startsWith('/inbox');
}
export const isPendingView = (pathname: string, params: ParamsType): boolean => {
return pathname === `/profile/${params.accountCommentIndex}`;
};
export const isPostView = (pathname: string, params: ParamsType): boolean => {
return params.subplebbitAddress && params.commentCid ? pathname.startsWith(`/p/${params.subplebbitAddress}/c/${params.commentCid}`) : false;
};
export const isProfileView = (pathname: string): boolean => {
return pathname.startsWith(`/profile`);
}
export const isSettingsView = (pathname: string): boolean => {
return pathname === '/settings';
}
export const isSubmitView = (pathname: string): boolean => {
return pathname === '/submit';
};
export const isSubplebbitView = (pathname: string, params: ParamsType): boolean => {
return params.subplebbitAddress ? pathname.startsWith(`/p/${params.subplebbitAddress}`) : false;
};
export const isSubplebbitSubmitView = (pathname: string, params: ParamsType): boolean => {
return params.subplebbitAddress ? pathname === `/p/${params.subplebbitAddress}/submit` : false;
};