feat: persist tags expanded state

This commit is contained in:
Mo
2022-02-08 22:27:00 -06:00
parent dcf07f70fd
commit 0c3d1fce0c
4 changed files with 18 additions and 9 deletions

View File

@@ -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(() => {

View File

@@ -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;
}