Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
feat: add support for tag hierachy preference (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Mar 22, 2022
1 parent 35f584f commit 643af58
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/screens/SideMenu/NoteSideMenu.tsx
Expand Up @@ -14,13 +14,15 @@ import {
} from '@Screens/screens';
import { Listed } from '@Screens/SideMenu/Listed';
import {
ApplicationEvent,
ButtonType,
ComponentArea,
ComponentMutator,
ContentType,
NoteMutator,
NoteViewController,
PayloadSource,
PrefKey,
SmartView,
SNComponent,
SNNote,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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.'
Expand Down

0 comments on commit 643af58

Please sign in to comment.