Manav Rathi hai 1 ano
pai
achega
2c46be6ded

+ 20 - 13
web/apps/photos/src/components/Upload/Uploader.tsx

@@ -131,12 +131,6 @@ export default function Uploader(props: Props) {
     const closeUploadProgress = () => setUploadProgressView(false);
     const showUserNameInputDialog = () => setUserNameInputDialogView(true);
 
-    // eslint-disable-next-line @typescript-eslint/no-unused-vars
-    const setCollectionName = (collectionName: string) => {
-        isPendingDesktopUpload.current = true;
-        pendingDesktopUploadCollectionName.current = collectionName;
-    };
-
     const handleChoiceModalClose = () => {
         setChoiceModalView(false);
         uploadRunning.current = false;
@@ -186,13 +180,26 @@ export default function Uploader(props: Props) {
                         );
                     }
                 });
-            /* TODO(MR): This is the connection point, implement
-            watcher.init(
-                setElectronFiles,
-                setCollectionName,
-                props.syncWithRemote,
-            );
-            */
+
+            // eslint-disable-next-line @typescript-eslint/no-unused-vars
+            const upload = (collectionName: string, filePaths: string[]) => {
+                isPendingDesktopUpload.current = true;
+                pendingDesktopUploadCollectionName.current = collectionName;
+
+                // TODO (MR):
+                // setElectronFiles(filePaths);
+            };
+
+            const requestSyncWithRemote = () => {
+                props.syncWithRemote().catch((e) => {
+                    log.error(
+                        "Ignoring error when syncing trash changes with remote",
+                        e,
+                    );
+                });
+            };
+
+            watcher.init(upload, requestSyncWithRemote);
         }
     }, [
         publicCollectionGalleryContext.accessedThroughSharedURL,

+ 26 - 28
web/apps/photos/src/services/watch.ts

@@ -57,11 +57,12 @@ class FolderWatcher {
      */
     private upload: (collectionName: string, filePaths: string[]) => void;
     /**
-     * A function to call when we want to sync with the backend.
+     * A function to call when we want to sync with the backend. It will
+     * initiate the sync but will not await its completion.
      *
      * This is passed as a param to {@link init}.
      */
-    private syncWithRemote: () => void;
+    private requestSyncWithRemote: () => void;
 
     /** A helper function that debounces invocations of {@link runNextEvent}. */
     private debouncedRunNextEvent: () => void;
@@ -80,10 +81,10 @@ class FolderWatcher {
      */
     init(
         upload: (collectionName: string, filePaths: string[]) => void,
-        syncWithRemote: () => void,
+        requestSyncWithRemote: () => void,
     ) {
         this.upload = upload;
-        this.syncWithRemote = syncWithRemote;
+        this.requestSyncWithRemote = requestSyncWithRemote;
         this.registerListeners();
         this.syncWithDisk();
     }
@@ -504,33 +505,30 @@ class FolderWatcher {
     }
 
     private async moveToTrash(syncedFiles: FolderWatch["syncedFiles"]) {
-        try {
-            const files = await getLocalFiles();
-            const toTrashFilesMap = new Map<number, FolderWatchSyncedFile>();
-            for (const file of syncedFiles) {
-                toTrashFilesMap.set(file.uploadedFileID, file);
-            }
-            const filesToTrash = files.filter((file) => {
-                if (toTrashFilesMap.has(file.id)) {
-                    const fileToTrash = toTrashFilesMap.get(file.id);
-                    if (fileToTrash.collectionID === file.collectionID) {
-                        return true;
-                    }
+        const files = await getLocalFiles();
+        const toTrashFilesMap = new Map<number, FolderWatchSyncedFile>();
+        for (const file of syncedFiles) {
+            toTrashFilesMap.set(file.uploadedFileID, file);
+        }
+        const filesToTrash = files.filter((file) => {
+            if (toTrashFilesMap.has(file.id)) {
+                const fileToTrash = toTrashFilesMap.get(file.id);
+                if (fileToTrash.collectionID === file.collectionID) {
+                    return true;
                 }
-            });
-            const groupFilesByCollectionId =
-                groupFilesBasedOnCollectionID(filesToTrash);
-
-            for (const [
-                collectionID,
-                filesToTrash,
-            ] of groupFilesByCollectionId.entries()) {
-                await removeFromCollection(collectionID, filesToTrash);
             }
-            this.syncWithRemote();
-        } catch (e) {
-            log.error("error while trashing by IDs", e);
+        });
+        const groupFilesByCollectionId =
+            groupFilesBasedOnCollectionID(filesToTrash);
+
+        for (const [
+            collectionID,
+            filesToTrash,
+        ] of groupFilesByCollectionId.entries()) {
+            await removeFromCollection(collectionID, filesToTrash);
         }
+
+        this.requestSyncWithRemote();
     }
 }