mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor(multiboards): remove time filter system end-to-end
Backend retention now keeps only recent posts, making the time filter UI and newerThan filtering obsolete. Deleted use-time-filter hook, canonical multiboard routes only, removed footer suggestions, dropped i18n keys.
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { normalizeMultiboardFeedPath } from '../route-utils';
|
||||
import { isFeedRoute, normalizeMultiboardFeedPath } from '../route-utils';
|
||||
|
||||
describe('normalizeMultiboardFeedPath', () => {
|
||||
it('normalizes /all/3 -> /all', () => {
|
||||
expect(normalizeMultiboardFeedPath('/all/3')).toBe('/all');
|
||||
});
|
||||
|
||||
it('normalizes /all/1w/3 -> /all/1w', () => {
|
||||
expect(normalizeMultiboardFeedPath('/all/1w/3')).toBe('/all/1w');
|
||||
});
|
||||
|
||||
it('normalizes /subs/2/settings -> /subs/settings', () => {
|
||||
expect(normalizeMultiboardFeedPath('/subs/2/settings')).toBe('/subs/settings');
|
||||
});
|
||||
@@ -21,9 +17,28 @@ describe('normalizeMultiboardFeedPath', () => {
|
||||
it('leaves non-multiboard paths unchanged', () => {
|
||||
expect(normalizeMultiboardFeedPath('/biz')).toBe('/biz');
|
||||
expect(normalizeMultiboardFeedPath('/biz/3')).toBe('/biz/3');
|
||||
expect(normalizeMultiboardFeedPath('/biz/1w/2')).toBe('/biz/1w/2');
|
||||
expect(normalizeMultiboardFeedPath('/biz/catalog/4')).toBe('/biz/catalog/4');
|
||||
expect(normalizeMultiboardFeedPath('/pending/0')).toBe('/pending/0');
|
||||
expect(normalizeMultiboardFeedPath('/')).toBe('/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isFeedRoute', () => {
|
||||
it('returns true for canonical multiboard paths', () => {
|
||||
expect(isFeedRoute('/all')).toBe(true);
|
||||
expect(isFeedRoute('/all/catalog')).toBe(true);
|
||||
expect(isFeedRoute('/subs')).toBe(true);
|
||||
expect(isFeedRoute('/subs/catalog')).toBe(true);
|
||||
expect(isFeedRoute('/mod')).toBe(true);
|
||||
expect(isFeedRoute('/mod/catalog')).toBe(true);
|
||||
expect(isFeedRoute('/all/3')).toBe(true);
|
||||
expect(isFeedRoute('/subs/2')).toBe(true);
|
||||
expect(isFeedRoute('/mod/catalog/4')).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false for time-filter paths', () => {
|
||||
expect(isFeedRoute('/all/24h')).toBe(false);
|
||||
expect(isFeedRoute('/subs/catalog/1w')).toBe(false);
|
||||
expect(isFeedRoute('/all/1w/3')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -109,19 +109,12 @@ export const isFeedRoute = (pathname: string): boolean => {
|
||||
if (normalizedPath.includes('/modqueue')) return false;
|
||||
|
||||
const pathWithoutSettings = normalizedPath.replace(/\/settings$/, '');
|
||||
|
||||
if (pathWithoutSettings.startsWith('/all')) return true;
|
||||
if (pathWithoutSettings.startsWith('/subs')) return true;
|
||||
if (pathWithoutSettings.startsWith('/mod')) return true;
|
||||
|
||||
const segments = pathWithoutSettings.split('/').filter(Boolean);
|
||||
if (segments.length >= 1) {
|
||||
if (segments.length === 1) return true;
|
||||
if (segments.length === 2 && segments[1] === 'catalog') return true;
|
||||
if (segments.length === 2 && (/^(?:\d+(?:h|d|w|m|y)|all)$/.test(segments[1]) || /^([1-9]|10)$/.test(segments[1]))) return true;
|
||||
if (segments.length === 3 && segments[1] === 'catalog' && /^(?:\d+(?:h|d|w|m|y)|all)$/.test(segments[2])) return true;
|
||||
if (segments.length === 3 && /^(?:\d+(?:h|d|w|m|y)|all)$/.test(segments[1]) && /^([1-9]|10)$/.test(segments[2])) return true;
|
||||
if (segments.length === 2 && segments[0] !== 'all' && segments[0] !== 'subs' && segments[0] !== 'mod' && /^([1-9]|10)$/.test(segments[1])) return true;
|
||||
if (segments.length === 2 && /^([1-9]|10)$/.test(segments[1])) return true;
|
||||
if (segments.length === 3 && segments[1] === 'catalog' && /^([1-9]|10)$/.test(segments[2])) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -163,8 +156,8 @@ function isMultiboardFeedPath(pathname: string): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize multiboard feed paths by removing trailing page-number segments (1–10),
|
||||
* while preserving /settings and valid time-filter segments.
|
||||
* Normalize multiboard feed paths by removing trailing page-number segments (1–10)
|
||||
* and preserving /settings.
|
||||
* Non-multiboard paths are returned unchanged.
|
||||
*/
|
||||
export const normalizeMultiboardFeedPath = (pathname: string): string => {
|
||||
|
||||
@@ -3,7 +3,6 @@ export type ParamsType = {
|
||||
boardIdentifier?: string;
|
||||
commentCid?: string;
|
||||
subplebbitAddress?: string; // deprecated, kept for backward compatibility
|
||||
timeFilterName?: string;
|
||||
};
|
||||
|
||||
export const isAllView = (pathname: string): boolean => {
|
||||
@@ -30,7 +29,7 @@ export const isBoardView = (pathname: string, params: ParamsType): boolean => {
|
||||
};
|
||||
|
||||
export const isCatalogView = (pathname: string, params: ParamsType): boolean => {
|
||||
const { boardIdentifier, subplebbitAddress, timeFilterName } = params;
|
||||
const { boardIdentifier, subplebbitAddress } = params;
|
||||
const identifier = boardIdentifier || subplebbitAddress;
|
||||
const decodedPathname = decodeURIComponent(pathname);
|
||||
|
||||
@@ -38,16 +37,10 @@ export const isCatalogView = (pathname: string, params: ParamsType): boolean =>
|
||||
(identifier && (decodedPathname === `/${identifier}/catalog` || decodedPathname === `/${identifier}/catalog/settings`)) ||
|
||||
decodedPathname === `/all/catalog` ||
|
||||
decodedPathname === `/all/catalog/settings` ||
|
||||
decodedPathname === `/all/catalog/${timeFilterName}` ||
|
||||
decodedPathname === `/all/catalog/${timeFilterName}/settings` ||
|
||||
decodedPathname === `/subs/catalog` ||
|
||||
decodedPathname === `/subs/catalog/settings` ||
|
||||
decodedPathname === `/subs/catalog/${timeFilterName}` ||
|
||||
decodedPathname === `/subs/catalog/${timeFilterName}/settings` ||
|
||||
decodedPathname === `/mod/catalog` ||
|
||||
decodedPathname === `/mod/catalog/settings` ||
|
||||
decodedPathname === `/mod/catalog/${timeFilterName}` ||
|
||||
decodedPathname === `/mod/catalog/${timeFilterName}/settings`
|
||||
decodedPathname === `/mod/catalog/settings`
|
||||
);
|
||||
};
|
||||
|
||||
@@ -83,17 +76,7 @@ export const isSettingsView = (pathname: string, params: ParamsType): boolean =>
|
||||
};
|
||||
|
||||
export const isSubscriptionsView = (pathname: string, params: ParamsType): boolean => {
|
||||
const { timeFilterName } = params;
|
||||
return (
|
||||
pathname === '/subs' ||
|
||||
pathname === '/subs/settings' ||
|
||||
pathname === `/subs/${timeFilterName}` ||
|
||||
pathname === `/subs/${timeFilterName}/settings` ||
|
||||
pathname === '/subs/catalog' ||
|
||||
pathname === '/subs/catalog/settings' ||
|
||||
pathname === `/subs/catalog/${timeFilterName}` ||
|
||||
pathname === `/subs/catalog/${timeFilterName}/settings`
|
||||
);
|
||||
return pathname === '/subs' || pathname === '/subs/settings' || pathname === '/subs/catalog' || pathname === '/subs/catalog/settings';
|
||||
};
|
||||
|
||||
export const isNotFoundView = (pathname: string, params: ParamsType): boolean => {
|
||||
|
||||
Reference in New Issue
Block a user