feat: add support for tag hierachy preference (#577)

This commit is contained in:
Aman Harwara
2022-03-23 00:23:43 +05:30
committed by GitHub
parent 35f584f4e2
commit 643af588da

View File

@@ -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<SNNote | undefined>(undefined);
const [selectedTags, setSelectedTags] = useState<SNTag[]>([]);
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) => {
<TagSelectionList
hasBottomPadding={Platform.OS === 'android'}
contentType={ContentType.Tag}
onTagSelect={item.onTagSelect}
onTagSelect={tag =>
item.onTagSelect(tag, shouldAddTagHierarchy)
}
selectedTags={item.selectedTags}
emptyPlaceholder={
'Create a new tag using the tag button in the bottom right corner.'