From cb5a9fc358bf608e64b95cb717d3b876ecf85d16 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Sat, 24 Jun 2023 14:38:43 +0500 Subject: [PATCH] mobile: fix editor stuck in loading state --- apps/mobile/app/components/list-items/note/wrapper.js | 2 +- apps/mobile/app/screens/editor/index.tsx | 1 + apps/mobile/app/screens/editor/loading.js | 4 ++-- apps/mobile/app/screens/editor/tiptap/use-editor.ts | 8 ++++++-- apps/mobile/app/screens/editor/tiptap/utils.ts | 2 +- apps/mobile/app/screens/editor/wrapper.js | 9 ++++++++- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/apps/mobile/app/components/list-items/note/wrapper.js b/apps/mobile/app/components/list-items/note/wrapper.js index 21df05dcf..616febf2d 100644 --- a/apps/mobile/app/components/list-items/note/wrapper.js +++ b/apps/mobile/app/components/list-items/note/wrapper.js @@ -68,7 +68,7 @@ export const openNote = async (item, isTrash, setSelectedItem, isSheet) => { clearSelection(); } - if (_note.conflicted) { + if (!_note.conflicted) { eSendEvent(eShowMergeDialog, _note); return; } diff --git a/apps/mobile/app/screens/editor/index.tsx b/apps/mobile/app/screens/editor/index.tsx index 1ee484c6d..56f80be41 100755 --- a/apps/mobile/app/screens/editor/index.tsx +++ b/apps/mobile/app/screens/editor/index.tsx @@ -128,6 +128,7 @@ const Editor = React.memo( const onError = useCallback(() => { renderKey.current = renderKey.current === `editor-0` ? `editor-1` : `editor-0`; + editor.state.current.ready = false; editor.setLoading(true); }, [editor]); diff --git a/apps/mobile/app/screens/editor/loading.js b/apps/mobile/app/screens/editor/loading.js index e0565773c..a07fc07dc 100644 --- a/apps/mobile/app/screens/editor/loading.js +++ b/apps/mobile/app/screens/editor/loading.js @@ -72,7 +72,7 @@ const EditorOverlay = ({ editorId = "", editor }) => { translateValue.value = 0; timers.current.error = setTimeout(() => { setError(true); - }, 15 * 1000); + }, 60 * 1000); } else { clearTimers(); const timeDiffSinceLoadStarted = @@ -109,7 +109,7 @@ const EditorOverlay = ({ editorId = "", editor }) => { clearTimers(); eUnSubscribeEvent("loadingNote" + editorId, load); }; - }, [editorId, load, translateValue]); + }, [editorId, load, translateValue, opacity]); const animatedStyle = useAnimatedStyle(() => { return { diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.ts index a4eb26005..96f05e107 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts @@ -369,6 +369,10 @@ export const useEditor = ( } else { overlay(true); } + if (!state.current.ready) { + currentNote.current = item as NoteType; + return; + } lastContentChangeTime.current = item.dateEdited; const nextSessionId = makeSessionId(item as NoteType); lockedSessionId.current = nextSessionId; @@ -595,7 +599,7 @@ export const useEditor = ( const onReady = useCallback(async () => { if (!(await isEditorLoaded(editorRef, sessionIdRef.current))) { - eSendEvent("webview_reset", "reset"); + eSendEvent("webview_reset"); } else { isDefaultEditor && restoreEditorState(); } @@ -611,13 +615,13 @@ export const useEditor = ( ); await commands.setSessionId(sessionIdRef.current); await onReady(); + state.current.ready = true; await commands.setSettings(); if (currentNote.current) { loadNote({ ...currentNote.current, forced: true }); } else { await commands.setPlaceholder(placeholderTip.current); } - state.current.ready = true; }, 1000); }, [ onReady, diff --git a/apps/mobile/app/screens/editor/tiptap/utils.ts b/apps/mobile/app/screens/editor/tiptap/utils.ts index f9b9a3e6d..feb6a2cc4 100644 --- a/apps/mobile/app/screens/editor/tiptap/utils.ts +++ b/apps/mobile/app/screens/editor/tiptap/utils.ts @@ -67,7 +67,7 @@ export async function isEditorLoaded( ref: RefObject, sessionId: string ) { - return await post(ref, sessionId, EditorEvents.status, undefined, 150); + return await post(ref, sessionId, EditorEvents.status); } export async function post( diff --git a/apps/mobile/app/screens/editor/wrapper.js b/apps/mobile/app/screens/editor/wrapper.js index 7b25edcf4..dad8fd292 100644 --- a/apps/mobile/app/screens/editor/wrapper.js +++ b/apps/mobile/app/screens/editor/wrapper.js @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import React, { useEffect } from "react"; +import React, { useEffect, useRef } from "react"; import { AppState, KeyboardAvoidingView, @@ -47,11 +47,18 @@ export const EditorWrapper = ({ width }) => { (state) => state.settings.introCompleted ); const keyboard = useKeyboard(); + const prevState = useRef(); const onAppStateChanged = async (state) => { + if (!prevState.current) { + prevState.current = state; + return; + } if (state === "active") { editorController.current.onReady(); editorController.current.overlay(false); + } else { + prevState.current = state; } };