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 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 {
|
function convertTimeStringToSeconds(timeString: string): number {
|
||||||
const match = timeString.match(/^(\d+)([hdwmy])$/);
|
const match = timeString.match(/^(\d+)([hdwmy])$/);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { getCommentMediaInfo, getHasThumbnail } from '../../lib/utils/media-util
|
|||||||
import { useDefaultSubplebbitAddresses, useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
|
import { useDefaultSubplebbitAddresses, useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
|
||||||
import { useResolvedSubplebbitAddress, useBoardPath } from '../../hooks/use-resolved-subplebbit-address';
|
import { useResolvedSubplebbitAddress, useBoardPath } from '../../hooks/use-resolved-subplebbit-address';
|
||||||
import { useFeedStateString } from '../../hooks/use-state-string';
|
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 useInterfaceSettingsStore from '../../stores/use-interface-settings-store';
|
||||||
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
||||||
import useSortingStore from '../../stores/use-sorting-store';
|
import useSortingStore from '../../stores/use-sorting-store';
|
||||||
@@ -34,7 +34,6 @@ const createThreadsWithoutImagesFilter = () => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export interface BoardProps {
|
export interface BoardProps {
|
||||||
// Props from FeedCacheContainer for cached feeds
|
|
||||||
feedCacheKey?: string;
|
feedCacheKey?: string;
|
||||||
viewType?: 'all' | 'subs' | 'mod' | 'board';
|
viewType?: 'all' | 'subs' | 'mod' | 'board';
|
||||||
boardIdentifier?: string;
|
boardIdentifier?: string;
|
||||||
@@ -48,12 +47,10 @@ const Board = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp, t
|
|||||||
const params = useParams();
|
const params = useParams();
|
||||||
const { hideThreadsWithoutImages } = useInterfaceSettingsStore();
|
const { hideThreadsWithoutImages } = useInterfaceSettingsStore();
|
||||||
|
|
||||||
// Use props from cache if provided, otherwise fall back to URL-derived values
|
|
||||||
const isInAllView = viewType ? viewType === 'all' : false;
|
const isInAllView = viewType ? viewType === 'all' : false;
|
||||||
const isInSubscriptionsView = viewType ? viewType === 'subs' : false;
|
const isInSubscriptionsView = viewType ? viewType === 'subs' : false;
|
||||||
const isInModView = viewType ? viewType === 'mod' : false;
|
const isInModView = viewType ? viewType === 'mod' : false;
|
||||||
|
|
||||||
// Resolve subplebbit address from cache props or URL
|
|
||||||
const defaultSubplebbits = useDefaultSubplebbits();
|
const defaultSubplebbits = useDefaultSubplebbits();
|
||||||
const resolvedAddressFromUrl = useResolvedSubplebbitAddress();
|
const resolvedAddressFromUrl = useResolvedSubplebbitAddress();
|
||||||
const subplebbitAddress = useMemo(() => {
|
const subplebbitAddress = useMemo(() => {
|
||||||
@@ -86,9 +83,9 @@ const Board = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp, t
|
|||||||
}, [isInAllView, isInSubscriptionsView, isInModView, subplebbitAddress, defaultSubplebbitAddresses, subscriptions, accountSubplebbitAddresses]);
|
}, [isInAllView, isInSubscriptionsView, isInModView, subplebbitAddress, defaultSubplebbitAddresses, subscriptions, accountSubplebbitAddresses]);
|
||||||
|
|
||||||
const { sortType } = useSortingStore();
|
const { sortType } = useSortingStore();
|
||||||
const { timeFilterSeconds, timeFilterName: timeFilterNameFromHook } = useTimeFilter();
|
const { timeFilterSeconds: timeFilterSecondsFromHook, timeFilterName: timeFilterNameFromHook } = useTimeFilter();
|
||||||
// Use time filter from cache if provided
|
|
||||||
const timeFilterName = timeFilterNameFromCache || timeFilterNameFromHook;
|
const timeFilterName = timeFilterNameFromCache || timeFilterNameFromHook;
|
||||||
|
const timeFilterSeconds = timeFilterNameFromCache ? timeFilterNameToSeconds(timeFilterNameFromCache) : timeFilterSecondsFromHook;
|
||||||
|
|
||||||
const feedOptions = {
|
const feedOptions = {
|
||||||
subplebbitAddresses,
|
subplebbitAddresses,
|
||||||
@@ -105,7 +102,6 @@ const Board = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp, t
|
|||||||
|
|
||||||
const setResetFunction = useFeedResetStore((state) => state.setResetFunction);
|
const setResetFunction = useFeedResetStore((state) => state.setResetFunction);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Only set reset function when this feed is visible
|
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
setResetFunction(reset);
|
setResetFunction(reset);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import useCatalogFeedRows from '../../hooks/use-catalog-feed-rows';
|
|||||||
import { useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
|
import { useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
|
||||||
import { useResolvedSubplebbitAddress, useBoardPath } from '../../hooks/use-resolved-subplebbit-address';
|
import { useResolvedSubplebbitAddress, useBoardPath } from '../../hooks/use-resolved-subplebbit-address';
|
||||||
import { useFeedStateString } from '../../hooks/use-state-string';
|
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 useWindowWidth from '../../hooks/use-window-width';
|
||||||
import useCatalogStyleStore from '../../stores/use-catalog-style-store';
|
import useCatalogStyleStore from '../../stores/use-catalog-style-store';
|
||||||
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
import useFeedResetStore from '../../stores/use-feed-reset-store';
|
||||||
@@ -124,7 +124,6 @@ const createCombinedFilter = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface CatalogProps {
|
export interface CatalogProps {
|
||||||
// Props from FeedCacheContainer for cached feeds
|
|
||||||
feedCacheKey?: string;
|
feedCacheKey?: string;
|
||||||
viewType?: 'all' | 'subs' | 'mod' | 'board';
|
viewType?: 'all' | 'subs' | 'mod' | 'board';
|
||||||
boardIdentifier?: string;
|
boardIdentifier?: string;
|
||||||
@@ -137,11 +136,9 @@ const Catalog = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp,
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
|
|
||||||
// Use props from cache if provided, otherwise fall back to URL-derived values
|
|
||||||
const isInAllView = viewType ? viewType === 'all' : false;
|
const isInAllView = viewType ? viewType === 'all' : false;
|
||||||
const isInSubscriptionsView = viewType ? viewType === 'subs' : false;
|
const isInSubscriptionsView = viewType ? viewType === 'subs' : false;
|
||||||
|
|
||||||
// Resolve subplebbit address from cache props or URL
|
|
||||||
const defaultSubplebbits = useDefaultSubplebbits();
|
const defaultSubplebbits = useDefaultSubplebbits();
|
||||||
const resolvedAddressFromUrl = useResolvedSubplebbitAddress();
|
const resolvedAddressFromUrl = useResolvedSubplebbitAddress();
|
||||||
const subplebbitAddress = useMemo(() => {
|
const subplebbitAddress = useMemo(() => {
|
||||||
@@ -186,10 +183,10 @@ const Catalog = ({ feedCacheKey, viewType, boardIdentifier: boardIdentifierProp,
|
|||||||
const columnCount = Math.floor(useWindowWidth() / columnWidth);
|
const columnCount = Math.floor(useWindowWidth() / columnWidth);
|
||||||
const postsPerPage = columnCount <= 2 ? 10 : columnCount === 3 ? 15 : columnCount === 4 ? 20 : 25;
|
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();
|
const { sortType } = useSortingStore();
|
||||||
// Use time filter from cache if provided
|
|
||||||
const timeFilterName = timeFilterNameFromCache || timeFilterNameFromHook;
|
const timeFilterName = timeFilterNameFromCache || timeFilterNameFromHook;
|
||||||
|
const timeFilterSeconds = timeFilterNameFromCache ? timeFilterNameToSeconds(timeFilterNameFromCache) : timeFilterSecondsFromHook;
|
||||||
|
|
||||||
// Create a stable callback for filter matching
|
// Create a stable callback for filter matching
|
||||||
const handleFilterMatch = useCallback((filterIndex: number, cid: string, subplebbitAddress: string) => {
|
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);
|
const setResetFunction = useFeedResetStore((state) => state.setResetFunction);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Only set reset function when this feed is visible
|
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
setResetFunction(reset);
|
setResetFunction(reset);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user