Update add/rm

This commit is contained in:
Manav Rathi 2024-04-18 21:32:15 +05:30
parent a9ccec6398
commit b49cb9dec2
No known key found for this signature in database
2 changed files with 13 additions and 12 deletions

View file

@ -92,10 +92,8 @@ export const WatchFolder: React.FC<WatchFolderProps> = ({ 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<WatchFolderProps> = ({ 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);

View file

@ -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<FolderWatch[]> {
@ -616,7 +621,7 @@ const onAddFile = async (path: string) => {
folderPath,
path: file.path,
});
}
};
async function diskFileRemovedCallback(filePath: string) {
const collectionNameAndFolderPath =