From 6d18383b22cbfd08cd7bf41b499a369d6de7c539 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed <40239442+ammarahm-ed@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:15:08 +0500 Subject: [PATCH] mobile: sync notes created from quick note/notification notes (#2428) * mobile: sync quick notes * Update apps/mobile/app/services/notifications.ts Co-authored-by: Abdullah Atta Signed-off-by: Ammar Ahmed <40239442+ammarahm-ed@users.noreply.github.com> * mobile: ensure full db init when sync is required --------- Signed-off-by: Ammar Ahmed <40239442+ammarahm-ed@users.noreply.github.com> Co-authored-by: Abdullah Atta --- apps/mobile/app/services/notifications.ts | 5 +++-- apps/mobile/share/share.js | 9 ++++----- apps/mobile/share/store.js | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.ts index ced4f0177..a495fe0ff 100644 --- a/apps/mobile/app/services/notifications.ts +++ b/apps/mobile/app/services/notifications.ts @@ -203,14 +203,15 @@ const onEvent = async ({ type, detail }: Event) => { reply_button_text: "Take note", reply_placeholder_text: "Write something..." }); - await initDatabase(false); + if (!db.isInitialized) await db.init(); + await db.notes?.init(); await db.notes?.add({ content: { type: "tiptap", data: `

${input}

` } }); - await db.notes?.init(); + await db.sync(false, false); useNoteStore.getState().setNotes(); break; } diff --git a/apps/mobile/share/share.js b/apps/mobile/share/share.js index bb94fdb6e..a757d34cb 100644 --- a/apps/mobile/share/share.js +++ b/apps/mobile/share/share.js @@ -26,12 +26,12 @@ import { Keyboard, Platform, SafeAreaView, + ScrollView, StatusBar, Text, TouchableOpacity, - useWindowDimensions, View, - ScrollView + useWindowDimensions } from "react-native"; import { SafeAreaProvider, @@ -45,10 +45,9 @@ import Storage from "../app/common/database/storage"; import { eSendEvent } from "../app/services/event-manager"; import { getElevation } from "../app/utils"; import { eOnLoadNote } from "../app/utils/events"; -import { sleep } from "../app/utils/time"; +import { Editor } from "./editor"; import { Search } from "./search"; import { initDatabase, useShareStore } from "./store"; -import { Editor } from "./editor"; const getLinkPreview = (url) => { return getPreviewData(url, 5000); }; @@ -315,7 +314,6 @@ const ShareView = ({ quicknote = false }) => { const onPress = async () => { setLoading(true); await initDatabase(); - await sleep(1500); if (!noteContent.current) return; if (appendNote && !db.notes.note(appendNote.id)) { useShareStore.getState().setAppendNote(null); @@ -358,6 +356,7 @@ const ShareView = ({ quicknote = false }) => { } } } + await db.sync(false, false); await Storage.write("notesAddedFromIntent", "added"); close(); setLoading(false); diff --git a/apps/mobile/share/store.js b/apps/mobile/share/store.js index 1b95f9e86..f550c4a87 100644 --- a/apps/mobile/share/store.js +++ b/apps/mobile/share/store.js @@ -29,8 +29,7 @@ import { db } from "../app/common/database"; export async function initDatabase() { if (!db.isInitialized) { - // Only load collections in database. - await db.initCollections(); + await db.init(); } await db.notes.init(); }