fix repeated syncs

This commit is contained in:
Abhinav-grd 2021-07-21 14:17:21 +05:30
parent 4b420b2144
commit 53c8c4db67

View file

@ -145,8 +145,8 @@ export default function Gallery() {
const loadingBar = useRef(null); const loadingBar = useRef(null);
const [searchMode, setSearchMode] = useState(false); const [searchMode, setSearchMode] = useState(false);
const [searchStats, setSearchStats] = useState(null); const [searchStats, setSearchStats] = useState(null);
const [syncInProgress, setSyncInProgress] = useState(true); const syncInProgress = useRef(true);
const [resync, setResync] = useState(false); const resync = useRef(false);
const [deleted, setDeleted] = useState<number[]>([]); const [deleted, setDeleted] = useState<number[]>([]);
const appContext = useContext(AppContext); const appContext = useContext(AppContext);
const [collectionFilesCount, setCollectionFilesCount] = useState<Map<number, number>>(); const [collectionFilesCount, setCollectionFilesCount] = useState<Map<number, number>>();
@ -191,11 +191,11 @@ export default function Gallery() {
useEffect(() => setCollectionNamerView(true), [collectionNamerAttributes]); useEffect(() => setCollectionNamerView(true), [collectionNamerAttributes]);
const syncWithRemote = async (force = false) => { const syncWithRemote = async (force = false) => {
if (syncInProgress && !force) { if (syncInProgress.current && !force) {
setResync(true); resync.current= true;
return; return;
} }
setSyncInProgress(true); syncInProgress.current=true;
try { try {
checkConnectivity(); checkConnectivity();
if (!(await isTokenValid())) { if (!(await isTokenValid())) {
@ -205,7 +205,6 @@ export default function Gallery() {
await billingService.updatePlans(); await billingService.updatePlans();
await billingService.syncSubscription(); await billingService.syncSubscription();
const collections = await syncCollections(); const collections = await syncCollections();
setCollections(collections);
const { files } = await syncFiles(collections, setFiles); const { files } = await syncFiles(collections, setFiles);
await initDerivativeState(collections, files); await initDerivativeState(collections, files);
} catch (e) { } catch (e) {
@ -232,9 +231,9 @@ export default function Gallery() {
} finally { } finally {
loadingBar.current?.complete(); loadingBar.current?.complete();
} }
setSyncInProgress(false); syncInProgress.current=false;
if (resync) { if (resync.current) {
setResync(false); resync.current=false;
syncWithRemote(); syncWithRemote();
} }
}; };