Skip to content

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

mobile: fix loading note in editor from notifications

Ammar Ahmedecf75a07e4e1
diff --git a/apps/mobile/app/hooks/use-app-events.tsx b/apps/mobile/app/hooks/use-app-events.tsx
index 83f20095b..a6d0e21cf 100644
--- a/apps/mobile/app/hooks/use-app-events.tsx
+++ b/apps/mobile/app/hooks/use-app-events.tsx
@@ -176,6 +176,7 @@ const onAppOpenedFromURL = async (event: { url: string }) => {
if (id) {
const note = await db.notes.note(id);
if (note) {
+ editorState().initialLoadCalled = true;
eSendEvent(eOnLoadNote, {
item: note
});
diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
index 0792b32b6..1ff484c9c 100644
--- a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
+++ b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
@@ -664,7 +664,8 @@ export const useEditorEvents = (
if (note) {
eSendEvent(eOnLoadNote, {
item: note,
- tabId: editorMessage.tabId
+ tabId: editorMessage.tabId,
+ loadedFromEditor: true
});
}
} else {
@@ -675,7 +676,8 @@ export const useEditorEvents = (
if (note) {
eSendEvent(eOnLoadNote, {
item: note,
- tabId: editorMessage.tabId
+ tabId: editorMessage.tabId,
+ loadedFromEditor: true
});
}
}
diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.ts
index a9ce25b60..27aaf092f 100644
--- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts
+++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts
@@ -508,9 +508,17 @@ export const useEditor = (
newTab?: boolean;
refresh?: boolean;
searchResultIndex?: number;
+ loadedFromEditor?: boolean;
}) => {
loadNoteMutex.runExclusive(async () => {
- if (!event) return;
+ if (
+ !event ||
+ (event.loadedFromEditor &&
+ event.item &&
+ event.item?.id !== useTabStore.getState().getCurrentNoteId())
+ ) {
+ return;
+ }
if (event.blockId) {
blockIdRef.current = event.blockId;
}
@@ -719,6 +727,7 @@ export const useEditor = (
}, 300);
}
postMessage(NativeEvents.theme, theme);
+ console.log("load finished", event.item?.id);
});
},
[
diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.ts
index f24fa6d97..05d2b32da 100644
--- a/apps/mobile/app/services/notifications.ts
+++ b/apps/mobile/app/services/notifications.ts
@@ -438,6 +438,7 @@ async function scheduleNotification(
async function loadNote(id: string, jump: boolean) {
if (!id || id === "notesnook_note_input") return;
+ editorState().initialLoadCalled = true;
const note = await db.notes.note(id);
if (!note) return;
if (!DDS.isTab && jump) {