From f0d43c9577c78b418ffa3f1f77835505c9ced0ad Mon Sep 17 00:00:00 2001 From: RoccoSmit Date: Wed, 2 Oct 2024 20:31:50 +1000 Subject: [PATCH] feat: add tag count to tree view (#3970) * Add tag count to tree view * Only display tag amounts > 1 * Updated tag amount var name to be more descriptive * - Moved display logic to html in return - Updated var names to closer match var passed in by TagSection component --- .../components/HomeSidebar/TagsSection.tsx | 2 +- web/src/components/TagTree.tsx | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/web/src/components/HomeSidebar/TagsSection.tsx b/web/src/components/HomeSidebar/TagsSection.tsx index 180d8340b..e41c8a155 100644 --- a/web/src/components/HomeSidebar/TagsSection.tsx +++ b/web/src/components/HomeSidebar/TagsSection.tsx @@ -86,7 +86,7 @@ const TagsSection = (props: Props) => { {tagAmounts.length > 0 ? ( treeMode ? ( - t[0])} /> + ) : (
{tagAmounts.map(([tag, amount]) => ( diff --git a/web/src/components/TagTree.tsx b/web/src/components/TagTree.tsx index 1544fc8df..6b1f6daef 100644 --- a/web/src/components/TagTree.tsx +++ b/web/src/components/TagTree.tsx @@ -6,36 +6,43 @@ import { useMemoFilterStore } from "@/store/v1"; interface Tag { key: string; text: string; + amount: number; subTags: Tag[]; } interface Props { - tags: string[]; + tagAmounts: [tag: string, amount: number][]; } -const TagTree = ({ tags: rawTags }: Props) => { +const TagTree = ({ tagAmounts: rawTagAmounts }: Props) => { const [tags, setTags] = useState([]); useEffect(() => { - const sortedTags = Array.from(rawTags).sort(); + const sortedTagAmounts = Array.from(rawTagAmounts).sort(); const root: Tag = { key: "", text: "", + amount: 0, subTags: [], }; - for (const tag of sortedTags) { - const subtags = tag.split("/"); + for (const tagAmount of sortedTagAmounts) { + const subtags = tagAmount[0].split("/"); let tempObj = root; let tagText = ""; for (let i = 0; i < subtags.length; i++) { const key = subtags[i]; + let amount: number = 0; + if (i === 0) { tagText += key; } else { tagText += "/" + key; } + if (sortedTagAmounts.some(([tag, amount]) => tag === tagText && amount > 1)) { + amount = tagAmount[1]; + } let obj = null; @@ -50,6 +57,7 @@ const TagTree = ({ tags: rawTags }: Props) => { obj = { key, text: tagText, + amount: amount, subTags: [], }; tempObj.subTags.push(obj); @@ -60,7 +68,7 @@ const TagTree = ({ tags: rawTags }: Props) => { } setTags(root.subTags as Tag[]); - }, [rawTags]); + }, [rawTagAmounts]); return (
@@ -111,7 +119,7 @@ const TagItemContainer: React.FC = (props: TagItemContain
- {tag.key} + {tag.key} {tag.amount > 1 && `(${tag.amount})`}