From 2cdab000fb1ca9039d878fc66b7e805184f69bac Mon Sep 17 00:00:00 2001 From: LyAhn Date: Sat, 6 Jun 2026 19:52:05 +0100 Subject: [PATCH] feat(discovery): surface all tags and guard folder removal Include tags used by a single image in Explore and invalidate the tag cache after edits so changes appear immediately. Add an accessible, time-limited confirmation step before removing indexed folders from the sidebar. --- src-tauri/src/db.rs | 2 +- src/components/Sidebar.tsx | 84 +++++++++++++++++++++++++++++--------- src/store.ts | 7 +++- 3 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src-tauri/src/db.rs b/src-tauri/src/db.rs index e571f9f..5df7fc2 100644 --- a/src-tauri/src/db.rs +++ b/src-tauri/src/db.rs @@ -1523,7 +1523,7 @@ pub fn get_explore_tags( JOIN images i ON i.id = t.image_id WHERE (?1 IS NULL OR i.folder_id = ?1) GROUP BY t.tag - HAVING COUNT(DISTINCT t.image_id) >= 2 + HAVING COUNT(DISTINCT t.image_id) >= 1 ORDER BY tag_count DESC, t.tag ASC LIMIT ?2", )?; diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 042b769..1aad9d5 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -1,3 +1,4 @@ +import { useEffect, useState } from "react"; import { open } from "@tauri-apps/plugin-dialog"; import { useGalleryStore, Folder, IndexProgress } from "../store"; @@ -12,6 +13,22 @@ function FolderItem({ }) { const { selectFolder, removeFolder, reindexFolder } = useGalleryStore(); const isIndexing = progress && !progress.done; + const [confirmingRemoval, setConfirmingRemoval] = useState(false); + + useEffect(() => { + if (!confirmingRemoval) return; + + const timeout = window.setTimeout(() => { + setConfirmingRemoval(false); + }, 4000); + + return () => window.clearTimeout(timeout); + }, [confirmingRemoval]); + + const handleRemove = async (event: React.MouseEvent) => { + event.stopPropagation(); + await removeFolder(folder.id); + }; return (
-
- - -
+ + +
+ ) : ( +
+ + +
+ )} ); } diff --git a/src/store.ts b/src/store.ts index 3fc221c..1aba18c 100644 --- a/src/store.ts +++ b/src/store.ts @@ -1360,15 +1360,20 @@ export const useGalleryStore = create((set, get) => ({ }, addUserTag: async (imageId, tag) => { - return invoke("add_user_tag", { + const result = await invoke("add_user_tag", { params: { image_id: imageId, tag }, }); + // Invalidate explore tags cache so new tag appears immediately + set({ exploreTagsFolderId: undefined }); + return result; }, removeTag: async (tagId) => { await invoke("remove_tag", { params: { tag_id: tagId }, }); + // Invalidate explore tags cache so removed tag disappears immediately + set({ exploreTagsFolderId: undefined }); }, loadDuplicateScanCache: async (folderId = null) => {