feat: add an option to auto expand subtags in tree mode (#4994)

This commit is contained in:
Huang Cheng Ting 2025-08-12 00:05:36 +09:00 committed by GitHub
parent 3fd305dce7
commit d86756f104
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 5 deletions

View File

@ -22,6 +22,7 @@ interface Props {
const TagsSection = observer((props: Props) => {
const t = useTranslate();
const [treeMode, setTreeMode] = useLocalStorage<boolean>("tag-view-as-tree", false);
const [treeAutoExpand, setTreeAutoExpand] = useLocalStorage<boolean>("tag-tree-auto-expand", false);
const renameTagDialog = useDialog();
const [selectedTag, setSelectedTag] = useState<string>("");
const tags = Object.entries(userStore.state.tagCount)
@ -75,13 +76,17 @@ const TagsSection = observer((props: Props) => {
<span className="text-sm shrink-0">{t("common.tree-mode")}</span>
<Switch checked={treeMode} onCheckedChange={(checked) => setTreeMode(checked)} />
</div>
<div className="w-auto flex flex-row justify-between items-center gap-2 p-1">
<span className="text-sm shrink-0">{t("common.auto-expand")}</span>
<Switch disabled={!treeMode} checked={treeAutoExpand} onCheckedChange={(checked) => setTreeAutoExpand(checked)} />
</div>
</PopoverContent>
</Popover>
)}
</div>
{tags.length > 0 ? (
treeMode ? (
<TagTree tagAmounts={tags} />
<TagTree tagAmounts={tags} expandSubTags={!!treeAutoExpand} />
) : (
<div className="w-full flex flex-row justify-start items-center relative flex-wrap gap-x-2 gap-y-1">
{tags.map(([tag, amount]) => (

View File

@ -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<Tag[]>([]);
useEffect(() => {
@ -74,7 +75,7 @@ const TagTree = ({ tagAmounts: rawTagAmounts }: Props) => {
return (
<div className="flex flex-col justify-start items-start relative w-full h-auto flex-nowrap gap-2 mt-1">
{tags.map((t, idx) => (
<TagItemContainer key={t.text + "-" + idx} tag={t} />
<TagItemContainer key={t.text + "-" + idx} tag={t} expandSubTags={expandSubTags} />
))}
</div>
);
@ -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) => (
<TagItemContainer key={st.text + "-" + idx} tag={st} />
<TagItemContainer key={st.text + "-" + idx} tag={st} expandSubTags={expandSubTags} />
))}
</div>
) : null}

View File

@ -21,6 +21,7 @@
"archive": "Archive",
"archived": "Archived",
"attachments": "Attachments",
"auto-expand": "Auto expand",
"avatar": "Avatar",
"basic": "Basic",
"beta": "Beta",