diff --git a/web/apps/photos/src/components/WatchFolder.tsx b/web/apps/photos/src/components/WatchFolder.tsx index f7951c5a87..26e9239116 100644 --- a/web/apps/photos/src/components/WatchFolder.tsx +++ b/web/apps/photos/src/components/WatchFolder.tsx @@ -92,10 +92,8 @@ export const WatchFolder: React.FC = ({ open, onClose }) => { } }; - const addWatch = async (folderPath: string, mapping: CollectionMapping) => { - await watcher.addWatch(folderPath, mapping); - setWatches(await watcher.getWatchMappings()); - }; + const addWatch = (folderPath: string, mapping: CollectionMapping) => + watcher.addWatch(folderPath, mapping).then((ws) => setWatches(ws)); const addNewWatch = async () => { const dirPath = await ensureElectron().selectDirectory(); @@ -104,10 +102,8 @@ export const WatchFolder: React.FC = ({ open, onClose }) => { } }; - const removeWatch = async (watch: FolderWatch) => { - await watcher.removeWatchForFolderPath(watch.folderPath); - setWatches(await watcher.getWatchMappings()); - }; + const removeWatch = async (watch: FolderWatch) => + watcher.removeWatch(watch.folderPath).then((ws) => setWatches(ws)); const closeChoiceModal = () => setChoiceModalOpen(false); diff --git a/web/apps/photos/src/services/watch.ts b/web/apps/photos/src/services/watch.ts index d773527438..d6bb4f4e92 100644 --- a/web/apps/photos/src/services/watch.ts +++ b/web/apps/photos/src/services/watch.ts @@ -113,17 +113,22 @@ class FolderWatcher { * * @param mapping The {@link CollectionMapping} to use to decide which * collection do files belonging to nested directories go to. + * + * @returns The updated list of watches. */ async addWatch(folderPath: string, mapping: CollectionMapping) { - await ensureElectron().watch.add(folderPath, mapping); + const watches = await ensureElectron().watch.add(folderPath, mapping); this.syncWithDisk(); + return watches; } /** * Remove the folder watch for the given root {@link folderPath}. + * + * @returns The updated list of watches. */ - async removeWatchForFolderPath(folderPath: string) { - await ensureElectron().removeWatchMapping(folderPath); + async removeWatch(folderPath: string) { + return await ensureElectron().watch.remove(folderPath); } async getWatchMappings(): Promise { @@ -616,7 +621,7 @@ const onAddFile = async (path: string) => { folderPath, path: file.path, }); -} +}; async function diskFileRemovedCallback(filePath: string) { const collectionNameAndFolderPath =