feat: persist tags expanded state
This commit is contained in:
@@ -41,7 +41,7 @@ export const TagsListItem: FunctionComponent<Props> = observer(
|
||||
|
||||
const premiumModal = usePremiumModal();
|
||||
|
||||
const [showChildren, setShowChildren] = useState(hasChildren);
|
||||
const [showChildren, setShowChildren] = useState(tag.expanded);
|
||||
const [hadChildren, setHadChildren] = useState(hasChildren);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -58,9 +58,12 @@ export const TagsListItem: FunctionComponent<Props> = observer(
|
||||
const toggleChildren = useCallback(
|
||||
(e: MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
setShowChildren((x) => !x);
|
||||
setShowChildren((x) => {
|
||||
tagsState.setExpanded(tag, !x);
|
||||
return !x;
|
||||
});
|
||||
},
|
||||
[setShowChildren]
|
||||
[setShowChildren, tag, tagsState]
|
||||
);
|
||||
|
||||
const selectCurrentTag = useCallback(() => {
|
||||
|
||||
@@ -267,6 +267,12 @@ export class TagsState {
|
||||
this.selected_ = tag;
|
||||
}
|
||||
|
||||
public setExpanded(tag: SNTag, exapnded: boolean) {
|
||||
this.application.changeAndSaveItem<TagMutator>(tag.uuid, (mutator) => {
|
||||
mutator.expanded = exapnded;
|
||||
});
|
||||
}
|
||||
|
||||
public get selectedUuid(): UuidString | undefined {
|
||||
return this.selected_?.uuid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user