From a1b4377f622b8194ffe467f2e81ee6bcd80c6ec8 Mon Sep 17 00:00:00 2001 From: PhilReact Date: Wed, 26 Mar 2025 22:34:14 +0200 Subject: [PATCH] cache refetch bugfix --- src/components/ResourceList/HorizontalPaginationList.tsx | 2 +- src/components/ResourceList/ResourceListDisplay.tsx | 9 +++++++-- src/components/ResourceList/VerticalPaginationList.tsx | 2 +- src/hooks/useIdentifiers.tsx | 8 +++++++- src/index.ts | 1 + src/state/cache.ts | 2 +- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/ResourceList/HorizontalPaginationList.tsx b/src/components/ResourceList/HorizontalPaginationList.tsx index 4dc26cd..dce68b6 100644 --- a/src/components/ResourceList/HorizontalPaginationList.tsx +++ b/src/components/ResourceList/HorizontalPaginationList.tsx @@ -77,7 +77,7 @@ const displayedItems = disablePagination ? items : items?.length < (displayedLim ))} > - {!disablePagination && displayedItems?.length >= (displayedLimit * 3) && ( + {(disablePagination || (!disablePagination && displayedItems?.length >= limit)) && ( { await onLoadMore(displayedLimit); diff --git a/src/components/ResourceList/ResourceListDisplay.tsx b/src/components/ResourceList/ResourceListDisplay.tsx index 2eb0c23..12296c3 100644 --- a/src/components/ResourceList/ResourceListDisplay.tsx +++ b/src/components/ResourceList/ResourceListDisplay.tsx @@ -137,6 +137,10 @@ export const MemorizedComponent = ({ const [isLoading, setIsLoading] = useState(list?.length > 0 ? false : true); const isListExpired = useCacheStore().isListExpired(listName) + const isListExpiredRef = useRef(true) + useEffect(()=> { + isListExpiredRef.current = isListExpired + }, [isListExpired]) const filterOutDeletedResources = useCacheStore((s) => s.filterOutDeletedResources); const deletedResources = useCacheStore((s) => s.deletedResources); @@ -230,6 +234,7 @@ const addItems = useListStore((s) => s.addItems); res(null) }, 500); }) + lastItemTimestampRef.current = null const parsedParams = {...(JSON.parse(memoizedParams))}; parsedParams.identifier = generatedIdentifier @@ -259,7 +264,7 @@ const addItems = useListStore((s) => s.addItems); useEffect(() => { if(!generatedIdentifier) return - if(!isListExpired && !initialized.current) { + if(!isListExpiredRef.current && !initialized.current) { setIsLoading(false) initialized.current = true return @@ -268,7 +273,7 @@ const addItems = useListStore((s) => s.addItems); sessionStorage.removeItem(`scroll-position-${listName}`); prevGeneratedIdentifierRef.current = generatedIdentifier getResourceList(); - }, [getResourceList, isListExpired, generatedIdentifier]); // Runs when dependencies change + }, [getResourceList, generatedIdentifier]); // Runs when dependencies change const {elementRef} = useScrollTracker(listName, list?.length > 0, disableScrollTracker); diff --git a/src/components/ResourceList/VerticalPaginationList.tsx b/src/components/ResourceList/VerticalPaginationList.tsx index 54b9ff8..4e53941 100644 --- a/src/components/ResourceList/VerticalPaginationList.tsx +++ b/src/components/ResourceList/VerticalPaginationList.tsx @@ -89,7 +89,7 @@ export const VerticalPaginatedList = ({ ); })} - {!disablePagination && displayedItems?.length >= (displayedLimit * 3) && ( + {(disablePagination || (!disablePagination && displayedItems?.length >= limit)) && ( { await onLoadMore(displayedLimit); diff --git a/src/hooks/useIdentifiers.tsx b/src/hooks/useIdentifiers.tsx index b47ae0c..ac86f37 100644 --- a/src/hooks/useIdentifiers.tsx +++ b/src/hooks/useIdentifiers.tsx @@ -25,6 +25,11 @@ export const useIdentifiers = (publicSalt: string, appName: string) => { const hashedQortalName = await hashWord(qortalName, EnumCollisionStrength.HIGH, publicSalt) return hashedQortalName }, [publicSalt]) + +const hashString = useCallback(async ( string: string, strength: EnumCollisionStrength)=> { + const hashedQortalName = await hashWord(string, strength, publicSalt) +return hashedQortalName +}, [publicSalt]) @@ -32,6 +37,7 @@ export const useIdentifiers = (publicSalt: string, appName: string) => { buildIdentifier: buildIdentifierFunc, buildSearchPrefix: buildSearchPrefixFunc, createSingleIdentifier, - hashQortalName + hashQortalName, + hashString }; }; diff --git a/src/index.ts b/src/index.ts index 2dd62f5..98b1c72 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import './index.css' +export { EnumCollisionStrength } from './utils/encryption'; export { showLoading, dismissToast, showError, showSuccess } from './utils/toast'; export { processText, sanitizedContent, extractComponents, handleClickText} from './utils/text'; export { RequestQueueWithPromise } from './utils/queue'; diff --git a/src/state/cache.ts b/src/state/cache.ts index c14f92c..cef9721 100644 --- a/src/state/cache.ts +++ b/src/state/cache.ts @@ -73,7 +73,7 @@ interface CacheState { export const useCacheStore = create ((set, get) => ({ - searchCacheExpiryDuration: 5 * 60 * 1000, + searchCacheExpiryDuration: 0.1 * 60 * 1000, resourceCacheExpiryDuration: 30 * 60 * 1000, resourceCache: {}, searchCache: {},