Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: editor tags

ammarahm-edf0505d8a9829
diff --git a/apps/mobile/src/screens/editor/tiptap/commands.ts b/apps/mobile/src/screens/editor/tiptap/commands.ts
index eb82fdf9c..bb5050e58 100644
--- a/apps/mobile/src/screens/editor/tiptap/commands.ts
+++ b/apps/mobile/src/screens/editor/tiptap/commands.ts
@@ -1,7 +1,9 @@
import { createRef, MutableRefObject, RefObject } from 'react';
import { Platform } from 'react-native';
import WebView from 'react-native-webview';
+import { db } from '../../../utils/database';
import { sleep } from '../../../utils/time';
+import { Note } from './types';
import { getResponse, randId, textInput } from './utils';
type Action = { job: string; id: string };
@@ -89,6 +91,23 @@ statusBar.current.set({date:"",saved:""});
`)
);
};
+
+ setTags = async (note: Note | null | undefined) => {
+ if (!note) return;
+ let tags = note.tags
+ .map((t: any) =>
+ db.tags?.tag(t) ? { title: db.tags.tag(t).title, alias: db.tags.tag(t).alias } : null
+ )
+ .filter((t: any) => t !== null);
+ await call(
+ this.ref,
+ fn(`
+ if (typeof editorTags !== "undefined" && editorTags.current) {
+ editorTags.current.setTags(${JSON.stringify(tags)});
+ }
+ `)
+ );
+ };
}
export default Commands;
diff --git a/apps/mobile/src/screens/editor/tiptap/useEditor.ts b/apps/mobile/src/screens/editor/tiptap/useEditor.ts
index f64038e94..c5514270a 100644
--- a/apps/mobile/src/screens/editor/tiptap/useEditor.ts
+++ b/apps/mobile/src/screens/editor/tiptap/useEditor.ts
@@ -4,11 +4,11 @@ import { DDS } from '../../../services/device-detection';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
import { TipManager } from '../../../services/tip-manager';
-import { useEditorStore } from '../../../stores/stores';
+import { useEditorStore, useTagStore } from '../../../stores/stores';
import { useThemeStore } from '../../../stores/theme';
import { db } from '../../../utils/database';
import { MMKV } from '../../../utils/database/mmkv';
-import { eOnLoadNote } from '../../../utils/events';
+import { eOnLoadNote, eOpenTagsDialog } from '../../../utils/events';
import { tabBarRef } from '../../../utils/global-refs';
import { timeConverter } from '../../../utils/time';
import Commands from './commands';
@@ -26,12 +26,17 @@ export const useEditor = () => {
const sessionHistoryId = useRef<number>();
const state = useRef<Partial<EditorState>>(defaultState);
const placeholderTip = useRef(TipManager.placeholderTip());
+ const tags = useTagStore(state => state.tags);
const postMessage = useCallback(
async (type: string, data: any) => await post(editorRef, type, data),
[]
);
+ useEffect(() => {
+ commands.setTags(currentNote.current);
+ }, [tags]);
+
useEffect(() => {
let unsub = useThemeStore.subscribe(state => {
postMessage(EditorEvents.theme, state.colors);
@@ -215,6 +220,7 @@ export const useEditor = () => {
await commands.setStatus(timeConverter(item.dateEdited), 'Saved');
await postMessage(EditorEvents.title, item.title);
await postMessage(EditorEvents.html, currentContent.current?.data);
+ await commands.setTags(currentNote.current);
overlay(false);
}
},
@@ -262,6 +268,28 @@ export const useEditor = () => {
title: message.value
});
break;
+ case 'editor-event:newtag':
+ if (!currentNote.current) return;
+ eSendEvent(eOpenTagsDialog, currentNote.current);
+ break;
+ case 'editor-event:tag':
+ if (message.value) {
+ if (!currentNote.current) return;
+ db.notes
+ //@ts-ignore
+ ?.note(currentNote.current?.id)
+ .untag(message.value)
+ .then(async () => {
+ useTagStore.getState().setTags();
+ await commands.setTags(currentNote.current);
+ Navigation.setRoutesToUpdate([
+ Navigation.routeNames.Notes,
+ Navigation.routeNames.NotesPage,
+ Navigation.routeNames.Tags
+ ]);
+ });
+ }
+ break;
}
eSendEvent(message.type, message);
},