Skip to content

Commit d86756f

Browse files
authored
feat: add an option to auto expand subtags in tree mode (#4994)
1 parent 3fd305d commit d86756f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

web/src/components/HomeSidebar/TagsSection.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface Props {
2222
const TagsSection = observer((props: Props) => {
2323
const t = useTranslate();
2424
const [treeMode, setTreeMode] = useLocalStorage<boolean>("tag-view-as-tree", false);
25+
const [treeAutoExpand, setTreeAutoExpand] = useLocalStorage<boolean>("tag-tree-auto-expand", false);
2526
const renameTagDialog = useDialog();
2627
const [selectedTag, setSelectedTag] = useState<string>("");
2728
const tags = Object.entries(userStore.state.tagCount)
@@ -75,13 +76,17 @@ const TagsSection = observer((props: Props) => {
7576
<span className="text-sm shrink-0">{t("common.tree-mode")}</span>
7677
<Switch checked={treeMode} onCheckedChange={(checked) => setTreeMode(checked)} />
7778
</div>
79+
<div className="w-auto flex flex-row justify-between items-center gap-2 p-1">
80+
<span className="text-sm shrink-0">{t("common.auto-expand")}</span>
81+
<Switch disabled={!treeMode} checked={treeAutoExpand} onCheckedChange={(checked) => setTreeAutoExpand(checked)} />
82+
</div>
7883
</PopoverContent>
7984
</Popover>
8085
)}
8186
</div>
8287
{tags.length > 0 ? (
8388
treeMode ? (
84-
<TagTree tagAmounts={tags} />
89+
<TagTree tagAmounts={tags} expandSubTags={!!treeAutoExpand} />
8590
) : (
8691
<div className="w-full flex flex-row justify-start items-center relative flex-wrap gap-x-2 gap-y-1">
8792
{tags.map(([tag, amount]) => (

web/src/components/TagTree.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ interface Tag {
1313

1414
interface Props {
1515
tagAmounts: [tag: string, amount: number][];
16+
expandSubTags: boolean;
1617
}
1718

18-
const TagTree = ({ tagAmounts: rawTagAmounts }: Props) => {
19+
const TagTree = ({ tagAmounts: rawTagAmounts, expandSubTags }: Props) => {
1920
const [tags, setTags] = useState<Tag[]>([]);
2021

2122
useEffect(() => {
@@ -74,23 +75,28 @@ const TagTree = ({ tagAmounts: rawTagAmounts }: Props) => {
7475
return (
7576
<div className="flex flex-col justify-start items-start relative w-full h-auto flex-nowrap gap-2 mt-1">
7677
{tags.map((t, idx) => (
77-
<TagItemContainer key={t.text + "-" + idx} tag={t} />
78+
<TagItemContainer key={t.text + "-" + idx} tag={t} expandSubTags={expandSubTags} />
7879
))}
7980
</div>
8081
);
8182
};
8283

8384
interface TagItemContainerProps {
8485
tag: Tag;
86+
expandSubTags: boolean;
8587
}
8688

8789
const TagItemContainer = observer((props: TagItemContainerProps) => {
88-
const { tag } = props;
90+
const { tag, expandSubTags } = props;
8991
const tagFilters = memoFilterStore.getFiltersByFactor("tagSearch");
9092
const isActive = tagFilters.some((f: MemoFilter) => f.value === tag.text);
9193
const hasSubTags = tag.subTags.length > 0;
9294
const [showSubTags, toggleSubTags] = useToggle(false);
9395

96+
useEffect(() => {
97+
toggleSubTags(expandSubTags);
98+
}, [expandSubTags]);
99+
94100
const handleTagClick = () => {
95101
if (isActive) {
96102
memoFilterStore.removeFilter((f: MemoFilter) => f.factor === "tagSearch" && f.value === tag.text);
@@ -140,7 +146,7 @@ const TagItemContainer = observer((props: TagItemContainerProps) => {
140146
}`}
141147
>
142148
{tag.subTags.map((st, idx) => (
143-
<TagItemContainer key={st.text + "-" + idx} tag={st} />
149+
<TagItemContainer key={st.text + "-" + idx} tag={st} expandSubTags={expandSubTags} />
144150
))}
145151
</div>
146152
) : null}

web/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"archive": "Archive",
2222
"archived": "Archived",
2323
"attachments": "Attachments",
24+
"auto-expand": "Auto expand",
2425
"avatar": "Avatar",
2526
"basic": "Basic",
2627
"beta": "Beta",

0 commit comments

Comments
 (0)