mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-29 00:20:04 +01:00
mobile: fix loading note in editor from notifications
Fix a race condition where the loading note gets replaced by editor's stored state on app launch
This commit is contained in:
@@ -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
|
||||
});
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
},
|
||||
[
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user