From 1199fd02eedf346ccdc035df951a329d5c44c6c2 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 3 Feb 2023 17:24:02 +0530 Subject: [PATCH] revert setFiles throttling --- src/pages/gallery/index.tsx | 47 ++----------------------------------- 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index ffdd15600..ecd0846db 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -88,7 +88,7 @@ import FixCreationTime, { } from 'components/FixCreationTime'; import { Collection, CollectionSummaries } from 'types/collection'; import { EnteFile } from 'types/file'; -import { GalleryContextType, SelectedState, SetFiles } from 'types/gallery'; +import { GalleryContextType, SelectedState } from 'types/gallery'; import { VISIBILITY_STATE } from 'types/magicMetadata'; import Collections from 'components/Collections'; import { GalleryNavbar } from 'components/pages/gallery/Navbar'; @@ -125,54 +125,11 @@ export const GalleryContext = createContext( defaultGalleryContext ); -type FilesFn = EnteFile[] | ((files: EnteFile[]) => EnteFile[]); - export default function Gallery() { const router = useRouter(); const [user, setUser] = useState(null); const [collections, setCollections] = useState(null); - const [files, setFilesOriginal] = useState(null); - - const filesUpdateInProgress = useRef(false); - const filesCount = useRef(0); - const newerFilesFN = useRef(null); - - const setFilesOriginalWithReSyncIfRequired: SetFiles = (filesFn) => { - setFilesOriginal((currentFiles) => { - let newFiles: EnteFile[]; - if (typeof filesFn === 'function') { - newFiles = filesFn(currentFiles); - } else { - newFiles = filesFn; - } - filesCount.current = newFiles?.length; - return newFiles; - }); - filesUpdateInProgress.current = false; - if (newerFilesFN.current) { - const newerFiles = newerFilesFN.current; - setTimeout(() => setFiles(newerFiles), 0); - newerFilesFN.current = null; - } - }; - - const setFiles: SetFiles = async (filesFn) => { - if (filesUpdateInProgress.current) { - newerFilesFN.current = filesFn; - return; - } - filesUpdateInProgress.current = true; - - if (!filesCount.current || filesCount.current < 5000) { - setFilesOriginalWithReSyncIfRequired(filesFn); - } else { - const waitTime = getData(LS_KEYS.WAIT_TIME) ?? 5000; - setTimeout( - () => setFilesOriginalWithReSyncIfRequired(filesFn), - waitTime - ); - } - }; + const [files, setFiles] = useState(null); const [favItemIds, setFavItemIds] = useState>();