diff --git a/web/apps/photos/src/components/WatchFolder.tsx b/web/apps/photos/src/components/WatchFolder.tsx index b5ff00b291..c0e7ab38ab 100644 --- a/web/apps/photos/src/components/WatchFolder.tsx +++ b/web/apps/photos/src/components/WatchFolder.tsx @@ -28,8 +28,8 @@ import { PICKED_UPLOAD_TYPE, UPLOAD_STRATEGY } from "constants/upload"; import { t } from "i18next"; import { AppContext } from "pages/_app"; import React, { useContext, useEffect, useState } from "react"; -import watchFolderService from "services/watch"; -import { WatchMapping } from "types/watchFolder"; +import watcher from "services/watch"; +import { WatchMapping as FolderWatch } from "types/watchFolder"; import { getImportSuggestion } from "utils/upload"; interface WatchFolderProps { @@ -38,7 +38,7 @@ interface WatchFolderProps { } export const WatchFolder: React.FC = ({ open, onClose }) => { - const [mappings, setMappings] = useState([]); + const [mappings, setMappings] = useState([]); const [inputFolderPath, setInputFolderPath] = useState(""); const [choiceModalOpen, setChoiceModalOpen] = useState(false); const appContext = useContext(AppContext); @@ -47,7 +47,7 @@ export const WatchFolder: React.FC = ({ open, onClose }) => { useEffect(() => { if (!electron) return; - watchFolderService.getWatchMappings().then((m) => setMappings(m)); + watcher.getWatchMappings().then((m) => setMappings(m)); }, []); useEffect(() => { @@ -64,7 +64,7 @@ export const WatchFolder: React.FC = ({ open, onClose }) => { for (let i = 0; i < folders.length; i++) { const folder: any = folders[i]; const path = (folder.path as string).replace(/\\/g, "/"); - if (await watchFolderService.isFolder(path)) { + if (await watcher.isFolder(path)) { await addFolderForWatching(path); } } @@ -91,7 +91,7 @@ export const WatchFolder: React.FC = ({ open, onClose }) => { }; const handleFolderSelection = async () => { - const folderPath = await watchFolderService.selectFolder(); + const folderPath = await watcher.selectFolder(); if (folderPath) { await addFolderForWatching(folderPath); } @@ -102,19 +102,18 @@ export const WatchFolder: React.FC = ({ open, onClose }) => { folderPath?: string, ) => { folderPath = folderPath || inputFolderPath; - await watchFolderService.addWatchMapping( + await watcher.addWatchMapping( folderPath.substring(folderPath.lastIndexOf("/") + 1), folderPath, uploadStrategy, ); setInputFolderPath(""); - setMappings(await watchFolderService.getWatchMappings()); + setMappings(await watcher.getWatchMappings()); }; - const handleRemoveWatchMapping = (mapping: WatchMapping) => { - watchFolderService - .mappingsAfterRemovingFolder(mapping.folderPath) - .then((ms) => setMappings(ms)); + const stopWatching = async (watch: FolderWatch) => { + await watcher.removeWatchForFolderPath(watch.folderPath); + setMappings(await watcher.getWatchMappings()); }; const closeChoiceModal = () => setChoiceModalOpen(false); @@ -144,9 +143,9 @@ export const WatchFolder: React.FC = ({ open, onClose }) => { -