From 72a1a886a79f1a25281c204d267d4b8a835cc749 Mon Sep 17 00:00:00 2001 From: LyAhn Date: Sat, 13 Jun 2026 23:10:09 +0100 Subject: [PATCH] fix(sidebar): refresh UI immediately when removing a library Removing a folder only reloaded the gallery when that exact folder was the active selection, so on All Media (or another view) its images stayed on screen until a manual refresh. Now the folder is dropped from the sidebar optimistically (instant feedback while the backend deletes its images), the gallery is always reloaded, and a failed delete resyncs the folder list. --- src/store.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/store.ts b/src/store.ts index 5177193..211c6ba 100644 --- a/src/store.ts +++ b/src/store.ts @@ -795,16 +795,28 @@ export const useGalleryStore = create((set, get) => ({ }, removeFolder: async (folderId) => { - await invoke("remove_folder", { folderId }); const { selectedFolderId, loadFolders, loadImages, loadBackgroundJobProgress } = get(); + // Optimistically drop it from the sidebar for instant feedback (the backend + // delete of its images/thumbnails can take a moment), clearing the active + // selection if it was this folder. + set((state) => { + const folders = state.folders.filter((folder) => folder.id !== folderId); + return selectedFolderId === folderId ? { folders, selectedFolderId: null } : { folders }; + }); + try { + await invoke("remove_folder", { folderId }); + } catch (error) { + // Removal failed — resync the authoritative list and surface the error. + await loadFolders(); + throw error; + } await loadFolders(); await loadBackgroundJobProgress(); - // Invalidate tag cloud and explore-tags cache since library content changed + // Invalidate tag cloud and explore-tags cache since library content changed. set({ tagCloudFolderId: undefined, tagCloudEntries: [], exploreTagsFolderId: undefined }); - if (selectedFolderId === folderId) { - set({ selectedFolderId: null }); - await loadImages(true); - } + // Always refresh the gallery: the removed folder's images may be on screen + // (e.g. in All Media), not only when that folder was the active selection. + await loadImages(true); }, reindexFolder: async (folderId) => {