From b652071703fd7e1ca06b504bd3b2184796e11bfa Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Tue, 4 Feb 2025 16:54:33 +0500 Subject: [PATCH] mobile: fix unlocking note with biometrics --- apps/mobile/app/screens/editor/index.tsx | 21 +++++++------------ .../app/screens/editor/tiptap/commands.ts | 8 ++++++- .../app/screens/editor/tiptap/use-editor.ts | 4 ++-- .../screens/editor/tiptap/use-tab-store.ts | 2 +- .../editor-mobile/src/components/editor.tsx | 8 +++---- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/apps/mobile/app/screens/editor/index.tsx b/apps/mobile/app/screens/editor/index.tsx index 95ce63715..0b939244c 100755 --- a/apps/mobile/app/screens/editor/index.tsx +++ b/apps/mobile/app/screens/editor/index.tsx @@ -248,14 +248,13 @@ const useLockedNoteHandler = () => { ); eSendEvent(eOnLoadNote, { - item: note - }); - - useTabStore.getState().updateTab(tabRef.current.id, { - session: { - locked: false - } + item: note, + refresh: true }); + } else { + if (tabRef.current && tabRef.current.session?.locked) { + editorController.current?.commands.focusPassInput(); + } } } catch (e) { console.error(e); @@ -310,12 +309,8 @@ const useLockedNoteHandler = () => { } } eSendEvent(eOnLoadNote, { - item: note - }); - useTabStore.getState().updateTab(tabRef.current.id, { - session: { - locked: false - } + item: note, + refresh: true }); } catch (e) { ToastManager.show({ diff --git a/apps/mobile/app/screens/editor/tiptap/commands.ts b/apps/mobile/app/screens/editor/tiptap/commands.ts index 50ab1429b..5119c8232 100644 --- a/apps/mobile/app/screens/editor/tiptap/commands.ts +++ b/apps/mobile/app/screens/editor/tiptap/commands.ts @@ -90,8 +90,14 @@ class Commands { const locked = useTabStore.getState().getTab(tabId)?.session?.locked; if (Platform.OS === "android") { - //this.ref.current?.requestFocus(); setTimeout(async () => { + if ( + locked && + useTabStore.getState().biometryAvailable && + useTabStore.getState().biometryEnrolled + ) + return; + if (!this.ref) return; textInput.current?.focus(); await this.sendCommand("focus", tabId, locked); diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.ts index 04750137c..bef1acfcf 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts @@ -501,6 +501,7 @@ export const useEditor = ( blockId?: string; session?: TabSessionItem; newTab?: boolean; + refresh?: boolean; }) => { loadNoteMutex.runExclusive(async () => { if (!event) return; @@ -574,11 +575,10 @@ export const useEditor = ( ? event.tabId : useTabStore.getState().currentTab; - console.log(tabId === useTabStore.getState().currentTab); - // Check if tab needs to be refreshed. if (!event.newTab) { if ( + !event.refresh && tabId && event.item.id === useTabStore.getState().getNoteIdForTab(tabId) && !localTabState.current?.needsRefresh( diff --git a/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts b/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts index 55a638e62..3166eedba 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-tab-store.ts @@ -358,8 +358,8 @@ export const useTabStore = create( if (note) { const isLocked = await db.vaults.itemExists(note); + session.noteLocked = isLocked; session.locked = isLocked; - session.noteLocked = isLocked && !session?.noteLocked; session.readonly = note.readonly; } else if (session.noteId) { diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsx index ef9b3ba90..874f19f77 100644 --- a/packages/editor-mobile/src/components/editor.tsx +++ b/packages/editor-mobile/src/components/editor.tsx @@ -556,7 +556,7 @@ const Tiptap = ({ )} - {controller.loading || tab.session?.noteLocked ? ( + {controller.loading || tab.session?.locked ? (