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.
This commit is contained in:
2026-06-13 23:10:09 +01:00
parent c15eed6655
commit 72a1a886a7
+18 -6
View File
@@ -795,16 +795,28 @@ export const useGalleryStore = create<GalleryState>((set, get) => ({
}, },
removeFolder: async (folderId) => { removeFolder: async (folderId) => {
await invoke("remove_folder", { folderId });
const { selectedFolderId, loadFolders, loadImages, loadBackgroundJobProgress } = get(); 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 loadFolders();
await loadBackgroundJobProgress(); 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 }); set({ tagCloudFolderId: undefined, tagCloudEntries: [], exploreTagsFolderId: undefined });
if (selectedFolderId === folderId) { // Always refresh the gallery: the removed folder's images may be on screen
set({ selectedFolderId: null }); // (e.g. in All Media), not only when that folder was the active selection.
await loadImages(true); await loadImages(true);
}
}, },
reindexFolder: async (folderId) => { reindexFolder: async (folderId) => {