From 53c8c4db67f504d0c84ce5ecd062687ea04bd0ee Mon Sep 17 00:00:00 2001 From: Abhinav-grd Date: Wed, 21 Jul 2021 14:17:21 +0530 Subject: [PATCH] fix repeated syncs --- src/pages/gallery/index.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 100fc1d5e..85f0e7f3c 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -145,8 +145,8 @@ export default function Gallery() { const loadingBar = useRef(null); const [searchMode, setSearchMode] = useState(false); const [searchStats, setSearchStats] = useState(null); - const [syncInProgress, setSyncInProgress] = useState(true); - const [resync, setResync] = useState(false); + const syncInProgress = useRef(true); + const resync = useRef(false); const [deleted, setDeleted] = useState([]); const appContext = useContext(AppContext); const [collectionFilesCount, setCollectionFilesCount] = useState>(); @@ -191,11 +191,11 @@ export default function Gallery() { useEffect(() => setCollectionNamerView(true), [collectionNamerAttributes]); const syncWithRemote = async (force = false) => { - if (syncInProgress && !force) { - setResync(true); + if (syncInProgress.current && !force) { + resync.current= true; return; } - setSyncInProgress(true); + syncInProgress.current=true; try { checkConnectivity(); if (!(await isTokenValid())) { @@ -205,7 +205,6 @@ export default function Gallery() { await billingService.updatePlans(); await billingService.syncSubscription(); const collections = await syncCollections(); - setCollections(collections); const { files } = await syncFiles(collections, setFiles); await initDerivativeState(collections, files); } catch (e) { @@ -232,9 +231,9 @@ export default function Gallery() { } finally { loadingBar.current?.complete(); } - setSyncInProgress(false); - if (resync) { - setResync(false); + syncInProgress.current=false; + if (resync.current) { + resync.current=false; syncWithRemote(); } };