From f51220c9a8a0278d885b02824934428e7ce564cd Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 4 Jul 2023 11:02:19 +0500 Subject: [PATCH] mobile: remove db.notes.init --- apps/mobile/app/hooks/use-app-events.js | 25 ++++++------------- .../mobile/app/navigation/navigation-stack.js | 4 +-- .../editor/tiptap/use-editor-events.ts | 6 ++++- apps/mobile/package-lock.json | 4 +-- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/apps/mobile/app/hooks/use-app-events.js b/apps/mobile/app/hooks/use-app-events.js index 55874ab29..8add889c0 100644 --- a/apps/mobile/app/hooks/use-app-events.js +++ b/apps/mobile/app/hooks/use-app-events.js @@ -562,20 +562,6 @@ export const useAppEvents = () => { } } - const loadNotes = useCallback(async () => { - if (appLocked) return; - - setImmediate(() => { - db.notes.init().then(() => { - Walkthrough.init(); - initialize(); - setImmediate(() => { - setLoading(false); - }); - }); - }); - }, [setLoading, appLocked]); - const IsDatabaseMigrationRequired = useCallback(() => { if (!db.migrations.required() || appLocked) return false; @@ -585,12 +571,13 @@ export const useAppEvents = () => { if (!db.isInitialized) { await db.init(); } - loadNotes(); + initialize(); + setLoading(false); }, disableClosing: true }); return true; - }, [appLocked, loadNotes]); + }, [appLocked]); useEffect(() => { if (!loading) { @@ -608,8 +595,10 @@ export const useAppEvents = () => { await db.init(); } if (IsDatabaseMigrationRequired()) return; - loadNotes(); - }, [IsDatabaseMigrationRequired, loadNotes]); + initialize(); + setLoading(false); + Walkthrough.init(); + }, [IsDatabaseMigrationRequired]); useEffect(() => { let sub; diff --git a/apps/mobile/app/navigation/navigation-stack.js b/apps/mobile/app/navigation/navigation-stack.js index d0498bf29..228e59fe3 100644 --- a/apps/mobile/app/navigation/navigation-stack.js +++ b/apps/mobile/app/navigation/navigation-stack.js @@ -188,7 +188,7 @@ const Tabs = React.memo(_Tabs, () => true); const _NavigationStack = () => { const clearSelection = useSelectionStore((state) => state.clearSelection); - + const loading = useNoteStore((state) => state.loading); const onStateChange = React.useCallback(() => { if (useSelectionStore.getState().selectionMode) { clearSelection(true); @@ -202,7 +202,7 @@ const _NavigationStack = () => { - + {loading ? null : } ); }; diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts b/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts index fdd4dd065..2859a0fd9 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts @@ -62,6 +62,7 @@ import { useDragState } from "../../settings/editor/state"; import { EventTypes } from "./editor-events"; import { EditorMessage, EditorProps, useEditorType } from "./types"; import { EditorEvents, editorState } from "./utils"; +import { useNoteStore } from "../../../stores/use-notes-store"; const publishNote = async (editor: useEditorType) => { const user = useUserStore.getState().user; @@ -130,6 +131,7 @@ export const useEditorEvents = ( const deviceMode = useSettingStore((state) => state.deviceMode); const fullscreen = useSettingStore((state) => state.fullscreen); const corsProxy = useSettingStore((state) => state.settings.corsProxy); + const loading = useNoteStore((state) => state.loading); const [dateFormat, timeFormat] = useSettingStore((state) => [ state.dateFormat, state.timeFormat @@ -168,6 +170,7 @@ export const useEditorEvents = ( }, [editor.commands, editor.postMessage]); useEffect(() => { + if (loading) return; editor.commands.setSettings({ deviceMode: deviceMode || "mobile", fullscreen: fullscreen || false, @@ -200,7 +203,8 @@ export const useEditorEvents = ( defaultFontSize, defaultFontFamily, dateFormat, - timeFormat + timeFormat, + loading ]); const onBackPress = useCallback(async () => { diff --git a/apps/mobile/package-lock.json b/apps/mobile/package-lock.json index d8b7a7d4c..59f5412be 100644 --- a/apps/mobile/package-lock.json +++ b/apps/mobile/package-lock.json @@ -1,12 +1,12 @@ { "name": "@notesnook/mobile", - "version": "2.5.3", + "version": "2.5.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@notesnook/mobile", - "version": "2.5.3", + "version": "2.5.4", "license": "GPL-3.0-or-later", "workspaces": [ "native/",