mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix: use stable time filter for virtuoso state key in cached feeds
This commit is contained in:
@@ -53,6 +53,34 @@ if (secondsSinceLastVisit > 30 * day) {
|
||||
|
||||
export const timeFilterNames = [lastVisitTimeFilterName, '1h', '12h', '24h', '48h', '1w', '1m', '1y', 'all'];
|
||||
|
||||
export const timeFilterNameToSeconds = (timeFilterName: string | undefined): number | undefined => {
|
||||
if (!timeFilterName || timeFilterName === 'all') return undefined;
|
||||
|
||||
if (timeFilterName in timeFilterNamesToSeconds) {
|
||||
return timeFilterNamesToSeconds[timeFilterName as keyof typeof timeFilterNamesToSeconds];
|
||||
}
|
||||
|
||||
const match = timeFilterName.match(/^(\d+)([hdwmy])$/);
|
||||
if (match) {
|
||||
const [, value, unit] = match;
|
||||
const numValue = parseInt(value, 10);
|
||||
switch (unit) {
|
||||
case 'h':
|
||||
return numValue * 60 * 60;
|
||||
case 'd':
|
||||
return numValue * 24 * 60 * 60;
|
||||
case 'w':
|
||||
return numValue * 7 * 24 * 60 * 60;
|
||||
case 'm':
|
||||
return numValue * 30 * 24 * 60 * 60;
|
||||
case 'y':
|
||||
return numValue * 365 * 24 * 60 * 60;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
function convertTimeStringToSeconds(timeString: string): number {
|
||||
const match = timeString.match(/^(\d+)([hdwmy])$/);
|
||||
if (!match) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import { getCommentMediaInfo, getHasThumbnail } from '../../lib/utils/media-util
|
||||
import { useDefaultSubplebbitAddresses, useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
|
||||
import { useResolvedSubplebbitAddress, useBoardPath } from '../../hooks/use-resolved-subplebbit-address';
|
||||
import { useFeedStateString } from '../../hooks/use-state-string';
|
||||
import useTimeFilter from '../../hooks/use-time-filter';
|
||||
import useTimeFilter, { timeFilterNameToSeconds } from '../../hooks/use-time-filter';
|
||||
import useInterfaceSettingsStore from '../../stores/use-interface-settings-store';
|
||||
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
||||
import useSortingStore from '../../stores/use-sorting-store';
|
||||
@@ -34,7 +34,6 @@ const createThreadsWithoutImagesFilter = () => ({
|
||||
});
|
||||
|
||||
export interface BoardProps {
|
||||
// Props from FeedCacheContainer for cached feeds
|
||||
feedCacheKey?: string;
|
||||
viewType?: 'all' | 'subs' | 'mod' | 'board';
|
||||
boardIdentifier?: string;
|
||||
@@ -48,12 +47,10 @@ const Board = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp, t
|
||||
const params = useParams();
|
||||
const { hideThreadsWithoutImages } = useInterfaceSettingsStore();
|
||||
|
||||
// Use props from cache if provided, otherwise fall back to URL-derived values
|
||||
const isInAllView = viewType ? viewType === 'all' : false;
|
||||
const isInSubscriptionsView = viewType ? viewType === 'subs' : false;
|
||||
const isInModView = viewType ? viewType === 'mod' : false;
|
||||
|
||||
// Resolve subplebbit address from cache props or URL
|
||||
const defaultSubplebbits = useDefaultSubplebbits();
|
||||
const resolvedAddressFromUrl = useResolvedSubplebbitAddress();
|
||||
const subplebbitAddress = useMemo(() => {
|
||||
@@ -86,9 +83,9 @@ const Board = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp, t
|
||||
}, [isInAllView, isInSubscriptionsView, isInModView, subplebbitAddress, defaultSubplebbitAddresses, subscriptions, accountSubplebbitAddresses]);
|
||||
|
||||
const { sortType } = useSortingStore();
|
||||
const { timeFilterSeconds, timeFilterName: timeFilterNameFromHook } = useTimeFilter();
|
||||
// Use time filter from cache if provided
|
||||
const { timeFilterSeconds: timeFilterSecondsFromHook, timeFilterName: timeFilterNameFromHook } = useTimeFilter();
|
||||
const timeFilterName = timeFilterNameFromCache || timeFilterNameFromHook;
|
||||
const timeFilterSeconds = timeFilterNameFromCache ? timeFilterNameToSeconds(timeFilterNameFromCache) : timeFilterSecondsFromHook;
|
||||
|
||||
const feedOptions = {
|
||||
subplebbitAddresses,
|
||||
@@ -105,7 +102,6 @@ const Board = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp, t
|
||||
|
||||
const setResetFunction = useFeedResetStore((state) => state.setResetFunction);
|
||||
useEffect(() => {
|
||||
// Only set reset function when this feed is visible
|
||||
if (isVisible) {
|
||||
setResetFunction(reset);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import useCatalogFeedRows from '../../hooks/use-catalog-feed-rows';
|
||||
import { useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
|
||||
import { useResolvedSubplebbitAddress, useBoardPath } from '../../hooks/use-resolved-subplebbit-address';
|
||||
import { useFeedStateString } from '../../hooks/use-state-string';
|
||||
import useTimeFilter from '../../hooks/use-time-filter';
|
||||
import useTimeFilter, { timeFilterNameToSeconds } from '../../hooks/use-time-filter';
|
||||
import useWindowWidth from '../../hooks/use-window-width';
|
||||
import useCatalogStyleStore from '../../stores/use-catalog-style-store';
|
||||
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
||||
@@ -124,7 +124,6 @@ const createCombinedFilter = (
|
||||
};
|
||||
|
||||
export interface CatalogProps {
|
||||
// Props from FeedCacheContainer for cached feeds
|
||||
feedCacheKey?: string;
|
||||
viewType?: 'all' | 'subs' | 'mod' | 'board';
|
||||
boardIdentifier?: string;
|
||||
@@ -137,11 +136,9 @@ const Catalog = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp,
|
||||
const location = useLocation();
|
||||
const params = useParams();
|
||||
|
||||
// Use props from cache if provided, otherwise fall back to URL-derived values
|
||||
const isInAllView = viewType ? viewType === 'all' : false;
|
||||
const isInSubscriptionsView = viewType ? viewType === 'subs' : false;
|
||||
|
||||
// Resolve subplebbit address from cache props or URL
|
||||
const defaultSubplebbits = useDefaultSubplebbits();
|
||||
const resolvedAddressFromUrl = useResolvedSubplebbitAddress();
|
||||
const subplebbitAddress = useMemo(() => {
|
||||
@@ -186,10 +183,10 @@ const Catalog = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp,
|
||||
const columnCount = Math.floor(useWindowWidth() / columnWidth);
|
||||
const postsPerPage = columnCount <= 2 ? 10 : columnCount === 3 ? 15 : columnCount === 4 ? 20 : 25;
|
||||
|
||||
const { timeFilterSeconds, timeFilterName: timeFilterNameFromHook } = useTimeFilter();
|
||||
const { timeFilterSeconds: timeFilterSecondsFromHook, timeFilterName: timeFilterNameFromHook } = useTimeFilter();
|
||||
const { sortType } = useSortingStore();
|
||||
// Use time filter from cache if provided
|
||||
const timeFilterName = timeFilterNameFromCache || timeFilterNameFromHook;
|
||||
const timeFilterSeconds = timeFilterNameFromCache ? timeFilterNameToSeconds(timeFilterNameFromCache) : timeFilterSecondsFromHook;
|
||||
|
||||
// Create a stable callback for filter matching
|
||||
const handleFilterMatch = useCallback((filterIndex: number, cid: string, subplebbitAddress: string) => {
|
||||
@@ -325,7 +322,6 @@ const Catalog = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp,
|
||||
|
||||
const setResetFunction = useFeedResetStore((state) => state.setResetFunction);
|
||||
useEffect(() => {
|
||||
// Only set reset function when this feed is visible
|
||||
if (isVisible) {
|
||||
setResetFunction(reset);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user