From 9d0c11b0513c58434348cbafee363c127f70dbd2 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 2 Aug 2023 13:09:56 +0500 Subject: [PATCH] web: unlock view should use base theme scope --- apps/web/src/app.tsx | 16 +++++++--------- .../unlock/{index.jsx => index.tsx} | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 15 deletions(-) rename apps/web/src/components/unlock/{index.jsx => index.tsx} (89%) diff --git a/apps/web/src/app.tsx b/apps/web/src/app.tsx index 465925b59..8c2bd6423 100644 --- a/apps/web/src/app.tsx +++ b/apps/web/src/app.tsx @@ -202,15 +202,13 @@ function DesktopAppContents({ bg: "background" }} > - - {isAppLoaded && ( - } - component={HashRouter} - condition={isAppLoaded} - /> - )} - + {isAppLoaded && ( + } + component={HashRouter} + condition={isAppLoaded} + /> + )} diff --git a/apps/web/src/components/unlock/index.jsx b/apps/web/src/components/unlock/index.tsx similarity index 89% rename from apps/web/src/components/unlock/index.jsx rename to apps/web/src/components/unlock/index.tsx index d0cde27e7..264e75873 100644 --- a/apps/web/src/components/unlock/index.jsx +++ b/apps/web/src/components/unlock/index.tsx @@ -27,17 +27,20 @@ import Field from "../field"; import { showToast } from "../../utils/toast"; import { ErrorText } from "../error-text"; -function Unlock(props) { +type UnlockProps = { + noteId: string; +}; +function Unlock(props: UnlockProps) { const { noteId } = props; const [isWrong, setIsWrong] = useState(false); const [isUnlocking, setIsUnlocking] = useState(false); const [isLoading, setIsLoading] = useState(true); - const passwordRef = useRef(); + const passwordRef = useRef(); const note = useMemo( - () => !isLoading && db.notes.note(noteId)?.data, + () => !isLoading && db.notes?.note(noteId)?.data, [noteId, isLoading] ); const openLockedSession = useEditorStore((store) => store.openLockedSession); @@ -45,14 +48,18 @@ function Unlock(props) { const setIsEditorOpen = useAppStore((store) => store.setIsEditorOpen); const submit = useCallback(async () => { + if (!passwordRef.current) return; setIsUnlocking(true); const password = passwordRef.current.value; try { if (!password) return; - const note = await db.vault.open(noteId, password); + const note = await db.vault?.open(noteId, password); openLockedSession(note); } catch (e) { - if (e.message.includes("ciphertext cannot be decrypted using that key")) { + if ( + e instanceof Error && + e.message.includes("ciphertext cannot be decrypted using that key") + ) { setIsWrong(true); } else { showToast("error", "Cannot unlock note: " + e); @@ -122,7 +129,7 @@ function Unlock(props) { sx={{ width: ["95%", "95%", "30%"] }} placeholder="Enter password" type="password" - onKeyUp={async (e) => { + onKeyUp={async (e: KeyboardEvent) => { if (e.key === "Enter") { await submit(); } else if (isWrong) {