From d86756f10432bfb45b07eb8a0ae046c13ffda13c Mon Sep 17 00:00:00 2001 From: Huang Cheng Ting <74168694+hchengting@users.noreply.github.com> Date: Tue, 12 Aug 2025 00:05:36 +0900 Subject: [PATCH] feat: add an option to auto expand subtags in tree mode (#4994) --- web/src/components/HomeSidebar/TagsSection.tsx | 7 ++++++- web/src/components/TagTree.tsx | 14 ++++++++++---- web/src/locales/en.json | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/web/src/components/HomeSidebar/TagsSection.tsx b/web/src/components/HomeSidebar/TagsSection.tsx index b8e5935a8..2eaeaf3d4 100644 --- a/web/src/components/HomeSidebar/TagsSection.tsx +++ b/web/src/components/HomeSidebar/TagsSection.tsx @@ -22,6 +22,7 @@ interface Props { const TagsSection = observer((props: Props) => { const t = useTranslate(); const [treeMode, setTreeMode] = useLocalStorage("tag-view-as-tree", false); + const [treeAutoExpand, setTreeAutoExpand] = useLocalStorage("tag-tree-auto-expand", false); const renameTagDialog = useDialog(); const [selectedTag, setSelectedTag] = useState(""); const tags = Object.entries(userStore.state.tagCount) @@ -75,13 +76,17 @@ const TagsSection = observer((props: Props) => { {t("common.tree-mode")} setTreeMode(checked)} /> +
+ {t("common.auto-expand")} + setTreeAutoExpand(checked)} /> +
)} {tags.length > 0 ? ( treeMode ? ( - + ) : (
{tags.map(([tag, amount]) => ( diff --git a/web/src/components/TagTree.tsx b/web/src/components/TagTree.tsx index 87b4a6c8d..14daca870 100644 --- a/web/src/components/TagTree.tsx +++ b/web/src/components/TagTree.tsx @@ -13,9 +13,10 @@ interface Tag { interface Props { tagAmounts: [tag: string, amount: number][]; + expandSubTags: boolean; } -const TagTree = ({ tagAmounts: rawTagAmounts }: Props) => { +const TagTree = ({ tagAmounts: rawTagAmounts, expandSubTags }: Props) => { const [tags, setTags] = useState([]); useEffect(() => { @@ -74,7 +75,7 @@ const TagTree = ({ tagAmounts: rawTagAmounts }: Props) => { return (
{tags.map((t, idx) => ( - + ))}
); @@ -82,15 +83,20 @@ const TagTree = ({ tagAmounts: rawTagAmounts }: Props) => { interface TagItemContainerProps { tag: Tag; + expandSubTags: boolean; } const TagItemContainer = observer((props: TagItemContainerProps) => { - const { tag } = props; + const { tag, expandSubTags } = props; const tagFilters = memoFilterStore.getFiltersByFactor("tagSearch"); const isActive = tagFilters.some((f: MemoFilter) => f.value === tag.text); const hasSubTags = tag.subTags.length > 0; const [showSubTags, toggleSubTags] = useToggle(false); + useEffect(() => { + toggleSubTags(expandSubTags); + }, [expandSubTags]); + const handleTagClick = () => { if (isActive) { memoFilterStore.removeFilter((f: MemoFilter) => f.factor === "tagSearch" && f.value === tag.text); @@ -140,7 +146,7 @@ const TagItemContainer = observer((props: TagItemContainerProps) => { }`} > {tag.subTags.map((st, idx) => ( - + ))}
) : null} diff --git a/web/src/locales/en.json b/web/src/locales/en.json index d4b165ad6..b9203cc3b 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -21,6 +21,7 @@ "archive": "Archive", "archived": "Archived", "attachments": "Attachments", + "auto-expand": "Auto expand", "avatar": "Avatar", "basic": "Basic", "beta": "Beta",