diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload/Uploader.tsx index ad0ff15b1..557fd743c 100644 --- a/web/apps/photos/src/components/Upload/Uploader.tsx +++ b/web/apps/photos/src/components/Upload/Uploader.tsx @@ -189,7 +189,6 @@ export default function Uploader(props: Props) { setElectronFiles, setCollectionName, props.syncWithRemote, - appContext.setIsFolderSyncRunning, ); } }, [ diff --git a/web/apps/photos/src/components/WatchFolder.tsx b/web/apps/photos/src/components/WatchFolder.tsx index 26e923911..78b1b2075 100644 --- a/web/apps/photos/src/components/WatchFolder.tsx +++ b/web/apps/photos/src/components/WatchFolder.tsx @@ -286,12 +286,10 @@ interface EntryHeadingProps { } const EntryHeading: React.FC = ({ watch }) => { - const appContext = useContext(AppContext); return ( {basename(watch.folderPath)} - {appContext.isFolderSyncRunning && - watcher.isSyncingWatch(watch) && } + {watcher.isSyncingWatch(watch) && } ); }; diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx index fb5c2ebbd..4b5fe3107 100644 --- a/web/apps/photos/src/pages/_app.tsx +++ b/web/apps/photos/src/pages/_app.tsx @@ -91,8 +91,6 @@ type AppContextType = { closeMessageDialog: () => void; setDialogMessage: SetDialogBoxAttributes; setNotificationAttributes: SetNotificationAttributes; - isFolderSyncRunning: boolean; - setIsFolderSyncRunning: (isRunning: boolean) => void; watchFolderView: boolean; setWatchFolderView: (isOpen: boolean) => void; watchFolderFiles: FileList; @@ -128,7 +126,6 @@ export default function App({ Component, pageProps }: AppProps) { useState(null); const [messageDialogView, setMessageDialogView] = useState(false); const [dialogBoxV2View, setDialogBoxV2View] = useState(false); - const [isFolderSyncRunning, setIsFolderSyncRunning] = useState(false); const [watchFolderView, setWatchFolderView] = useState(false); const [watchFolderFiles, setWatchFolderFiles] = useState(null); const isMobile = useMediaQuery("(max-width:428px)"); @@ -403,8 +400,6 @@ export default function App({ Component, pageProps }: AppProps) { finishLoading, closeMessageDialog, setDialogMessage, - isFolderSyncRunning, - setIsFolderSyncRunning, watchFolderView, setWatchFolderView, watchFolderFiles, diff --git a/web/apps/photos/src/services/watch.ts b/web/apps/photos/src/services/watch.ts index d6bb4f4e9..de72b7246 100644 --- a/web/apps/photos/src/services/watch.ts +++ b/web/apps/photos/src/services/watch.ts @@ -30,21 +30,22 @@ import { getLocalFiles } from "./fileService"; * works when we're running inside our desktop app. */ class FolderWatcher { - private eventQueue: WatchEvent[] = []; - private currentEvent: WatchEvent; - private currentlySyncedMapping: FolderWatch; - private trashingDirQueue: string[] = []; - private isEventRunning: boolean = false; /** `true` if we are currently uploading */ private uploadRunning = false; /** `true` if we are temporarily paused to let a user upload go through */ private isPaused = false; + /** Pending file system events that we need to process */ + private eventQueue: WatchEvent[] = []; + private currentEvent: WatchEvent; + // TODO(MR): dedup if possible + private isEventRunning: boolean = false; + private currentlySyncedMapping: FolderWatch; + private trashingDirQueue: string[] = []; private filePathToUploadedFileIDMap = new Map(); private unUploadableFilePaths = new Set(); private setElectronFiles: (files: ElectronFile[]) => void; private setCollectionName: (collectionName: string) => void; private syncWithRemote: () => void; - private setWatchFolderServiceIsRunning: (isRunning: boolean) => void; private debouncedRunNextEvent: () => void; constructor() { @@ -105,7 +106,10 @@ class FolderWatcher { * {@link watch} */ isSyncingWatch(watch: FolderWatch) { - return this.currentEvent?.folderPath === watch.folderPath; + return ( + this.isEventRunning && + this.currentEvent?.folderPath == watch.folderPath + ); } /** @@ -184,11 +188,6 @@ class FolderWatcher { ); } - private setIsEventRunning(isEventRunning: boolean) { - this.isEventRunning = isEventRunning; - this.setWatchFolderServiceIsRunning(isEventRunning); - } - private async runNextEvent() { try { if ( @@ -223,12 +222,12 @@ class FolderWatcher { this.currentEvent = event; this.currentlySyncedMapping = mapping; - this.setIsEventRunning(true); + this.isEventRunning = true; if (event.type === "upload") { this.processUploadEvent(); } else { await this.processTrashEvent(); - this.setIsEventRunning(false); + this.isEventRunning = false; setTimeout(() => this.runNextEvent(), 0); } } catch (e) { @@ -372,7 +371,7 @@ class FolderWatcher { } private runPostUploadsAction() { - this.setIsEventRunning(false); + this.isEventRunning = false; this.uploadRunning = false; this.runNextEvent(); }