fix: file deletion logic to update recent files and handle errors #146

This commit is contained in:
Linus Rath
2026-04-03 14:20:06 +02:00
parent 5aad97d64e
commit c53ff5a30a
2 changed files with 21 additions and 3 deletions
+10 -2
View File
@@ -408,7 +408,7 @@ export const useFileStore = create<FileState>((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<FileState>((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<FileState>((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();
},