diff --git a/lib/jmap/client.ts b/lib/jmap/client.ts index 8b00f3f4..dc88b49f 100644 --- a/lib/jmap/client.ts +++ b/lib/jmap/client.ts @@ -4153,6 +4153,7 @@ export class JMAPClient implements IJMAPClient { [["FileNode/set", { accountId, destroy: ids, + onDestroyRemoveChildren: true, }, "fns0"]], this.fileUsing(), ); @@ -4161,9 +4162,18 @@ export class JMAPClient implements IJMAPClient { if (!result || result[0] === "error") { throw new Error(result?.[1]?.description || "FileNode/set destroy failed"); } + + const notDestroyedMap: Record = result[1].notDestroyed || {}; + const notDestroyedIds = Object.keys(notDestroyedMap); + + if (notDestroyedIds.length > 0) { + const firstError = notDestroyedMap[notDestroyedIds[0]]; + throw new Error(firstError?.description || `Failed to delete ${notDestroyedIds.length} file(s)`); + } + return { destroyed: result[1].destroyed || [], - notDestroyed: result[1].notDestroyed ? Object.keys(result[1].notDestroyed) : [], + notDestroyed: [], }; } diff --git a/stores/file-store.ts b/stores/file-store.ts index f053b350..5b78e175 100644 --- a/stores/file-store.ts +++ b/stores/file-store.ts @@ -408,7 +408,7 @@ export const useFileStore = create((set, get) => ({ }, deleteResource: async (name: string) => { - const { client, resources, refresh } = get(); + const { client, resources, recentFiles, refresh } = get(); if (!client) return; const resource = resources.find(r => r.name === name); @@ -428,11 +428,15 @@ export const useFileStore = create((set, get) => ({ } await client.destroyFileNodes(idsToDelete); + const deletedIdSet = new Set(idsToDelete); + const nextRecentFiles = recentFiles.filter(r => !deletedIdSet.has(r.id)); + set({ recentFiles: nextRecentFiles }); + try { localStorage.setItem('files-recent-files', JSON.stringify(nextRecentFiles)); } catch { /* ignore */ } await refresh(); }, deleteResources: async (names: string[]) => { - const { client, resources, refresh } = get(); + const { client, resources, recentFiles, refresh } = get(); if (!client) return; const idsToDelete: string[] = []; @@ -457,7 +461,11 @@ export const useFileStore = create((set, get) => ({ if (idsToDelete.length === 0) return; await client.destroyFileNodes(idsToDelete); + const deletedIdSet = new Set(idsToDelete); + const nextRecentFiles = recentFiles.filter(r => !deletedIdSet.has(r.id)); set({ selectedResources: new Set() }); + set({ recentFiles: nextRecentFiles }); + try { localStorage.setItem('files-recent-files', JSON.stringify(nextRecentFiles)); } catch { /* ignore */ } await refresh(); },