Browse Source

remove files of deleted collections

Abhinav-grd 4 years ago
parent
commit
5c5a161999
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/services/fileService.ts

+ 6 - 1
src/services/fileService.ts

@@ -78,7 +78,11 @@ export const fetchFiles = async (
     let files = await localFiles();
     let files = await localFiles();
     const collectionUpdationTime = new Map<string, string>();
     const collectionUpdationTime = new Map<string, string>();
     let fetchedFiles = [];
     let fetchedFiles = [];
+    let deletedCollection = new Set<string>();
     for (let collection of collections) {
     for (let collection of collections) {
+        if (collection.isDeleted) {
+            deletedCollection.add(collection.id);
+        }
         const files = await getFiles(collection, null, 100, token);
         const files = await getFiles(collection, null, 100, token);
         fetchedFiles.push(...files);
         fetchedFiles.push(...files);
         collectionUpdationTime.set(collection.id, files.length > 0 ? files.slice(-1)[0].updationTime.toString() : "0");
         collectionUpdationTime.set(collection.id, files.length > 0 ? files.slice(-1)[0].updationTime.toString() : "0");
@@ -93,8 +97,9 @@ export const fetchFiles = async (
     });
     });
     files = [];
     files = [];
     for (const [_, file] of latestFiles) {
     for (const [_, file] of latestFiles) {
-        if (!file.isDeleted)
+        if (!(file.isDeleted || deletedCollection.has(file.collectionID.toString()))) {
             files.push(file);
             files.push(file);
+        }
     }
     }
     files = files.sort(
     files = files.sort(
         (a, b) => b.metadata.creationTime - a.metadata.creationTime
         (a, b) => b.metadata.creationTime - a.metadata.creationTime