diff --git a/src/screens/SideMenu/NoteSideMenu.tsx b/src/screens/SideMenu/NoteSideMenu.tsx index 3493983c..f301b996 100644 --- a/src/screens/SideMenu/NoteSideMenu.tsx +++ b/src/screens/SideMenu/NoteSideMenu.tsx @@ -14,6 +14,7 @@ import { } from '@Screens/screens'; import { Listed } from '@Screens/SideMenu/Listed'; import { + ApplicationEvent, ButtonType, ComponentArea, ComponentMutator, @@ -21,6 +22,7 @@ import { NoteMutator, NoteViewController, PayloadSource, + PrefKey, SmartView, SNComponent, SNNote, @@ -114,6 +116,28 @@ export const NoteSideMenu = React.memo((props: Props) => { ); const [note, setNote] = useState(undefined); const [selectedTags, setSelectedTags] = useState([]); + + const [shouldAddTagHierarchy, setShouldAddTagHierachy] = useState(() => + application!.getPreference(PrefKey.NoteAddToParentFolders, true) + ); + + useEffect(() => { + if (!application) return; + + const removeEventObserver = application.addSingleEventObserver( + ApplicationEvent.PreferencesChanged, + async () => { + setShouldAddTagHierachy( + application.getPreference(PrefKey.NoteAddToParentFolders, true) + ); + } + ); + + return () => { + removeEventObserver(); + }; + }, [application]); + const components = useEditorComponents(); const [changeNote] = useChangeNote(note, editor); @@ -572,7 +596,7 @@ export const NoteSideMenu = React.memo((props: Props) => { ]); const onTagSelect = useCallback( - async (tag: SNTag | SmartView) => { + async (tag: SNTag | SmartView, addTagHierachy: boolean) => { const isSelected = selectedTags.findIndex(selectedTag => selectedTag.uuid === tag.uuid) > -1; @@ -583,7 +607,11 @@ export const NoteSideMenu = React.memo((props: Props) => { mutator.removeItemAsRelationship(note); }); } else { - await application?.items.addTagToNote(note, tag as SNTag, true); + await application?.items.addTagToNote( + note, + tag as SNTag, + addTagHierachy + ); } } reloadTags(); @@ -645,7 +673,9 @@ export const NoteSideMenu = React.memo((props: Props) => { + item.onTagSelect(tag, shouldAddTagHierarchy) + } selectedTags={item.selectedTags} emptyPlaceholder={ 'Create a new tag using the tag button in the bottom right corner.'