Reduce API

This commit is contained in:
Manav Rathi 2024-04-16 16:17:27 +05:30
parent afec29d6e7
commit 9a6f3133b1
No known key found for this signature in database
2 changed files with 12 additions and 9 deletions

View file

@ -111,9 +111,10 @@ export const WatchFolder: React.FC<WatchFolderProps> = ({ open, onClose }) => {
setMappings(await watchFolderService.getWatchMappings());
};
const handleRemoveWatchMapping = async (mapping: WatchMapping) => {
await watchFolderService.removeWatchMapping(mapping.folderPath);
setMappings(await watchFolderService.getWatchMappings());
const handleRemoveWatchMapping = (mapping: WatchMapping) => {
watchFolderService
.mappingsAfterRemovingFolder(mapping.folderPath)
.then((ms) => setMappings(ms));
};
const closeChoiceModal = () => setChoiceModalOpen(false);

View file

@ -1,3 +1,8 @@
/**
* @file Interface with the Node.js layer of our desktop app to provide the
* watch folders functionality.
*/
import { ensureElectron } from "@/next/electron";
import log from "@/next/log";
import { UPLOAD_RESULT, UPLOAD_STRATEGY } from "constants/upload";
@ -190,12 +195,9 @@ class WatchFolderService {
}
}
async removeWatchMapping(folderPath: string) {
try {
await ensureElectron().removeWatchMapping(folderPath);
} catch (e) {
log.error("error while removing watch mapping", e);
}
async mappingsAfterRemovingFolder(folderPath: string) {
await ensureElectron().removeWatchMapping(folderPath);
return await this.getWatchMappings();
}
async getWatchMappings(): Promise<WatchMapping[]> {