diff --git a/apps/web/src/components/diff-viewer/index.js b/apps/web/src/components/diff-viewer/index.js index e8f4f2538..d0625eeb4 100644 --- a/apps/web/src/components/diff-viewer/index.js +++ b/apps/web/src/components/diff-viewer/index.js @@ -35,7 +35,7 @@ function DiffViewer(props) { const setIsEditorOpen = useAppStore((store) => store.setIsEditorOpen); const sync = useAppStore((store) => store.sync); - const clearSession = useEditorStore((store) => store.clearSession); + const openSession = useEditorStore((store) => store.openSession); const [conflictedNote, setConflictedNote] = useState(); const [remoteContent, setRemoteContent] = useState(); const [localContent, setLocalContent] = useState(); @@ -98,7 +98,10 @@ function DiffViewer(props) { hashNavigate(`/notes/create`, { replace: true }); return; } - notesStore.setSelectedNote(noteId); + + await openSession(noteId); + setIsEditorOpen(true); + note = note.data; const content = await db.content.raw(note.contentId); @@ -114,12 +117,7 @@ function DiffViewer(props) { setHtmlDiff({ before: content.data, after: content.conflicted.data }); })(); - }, [noteId, resolveConflict]); - - useEffect(() => { - clearSession(false); - setIsEditorOpen(true); - }, [setIsEditorOpen, clearSession]); + }, [noteId, openSession, setIsEditorOpen, resolveConflict]); if (!conflictedNote || !localContent || !remoteContent) return null; return ( diff --git a/apps/web/src/components/unlock/index.js b/apps/web/src/components/unlock/index.js index 447503edd..c24332276 100644 --- a/apps/web/src/components/unlock/index.js +++ b/apps/web/src/components/unlock/index.js @@ -23,20 +23,25 @@ import * as Icon from "../icons"; import { db } from "../../common/db"; import { useStore as useEditorStore } from "../../stores/editor-store"; import { useStore as useAppStore } from "../../stores/app-store"; -import { useStore as useNoteStore } from "../../stores/note-store"; import Field from "../field"; import { showToast } from "../../utils/toast"; function Unlock(props) { const { noteId } = props; - const note = useMemo(() => db.notes.note(noteId)?.data, [noteId]); - const passwordRef = useRef(); + const [isWrong, setIsWrong] = useState(false); const [isUnlocking, setIsUnlocking] = useState(false); + const [isLoading, setIsLoading] = useState(true); + + const passwordRef = useRef(); + + const note = useMemo( + () => !isLoading && db.notes.note(noteId)?.data, + [noteId, isLoading] + ); const openLockedSession = useEditorStore((store) => store.openLockedSession); - const clearSession = useEditorStore((store) => store.clearSession); + const openSession = useEditorStore((store) => store.openSession); const setIsEditorOpen = useAppStore((store) => store.setIsEditorOpen); - const setSelectedNote = useNoteStore((store) => store.setSelectedNote); const submit = useCallback(async () => { setIsUnlocking(true); @@ -58,10 +63,15 @@ function Unlock(props) { }, [setIsWrong, noteId, openLockedSession]); useEffect(() => { - clearSession(false); - setIsEditorOpen(true); - setTimeout(() => setSelectedNote(noteId)); - }, [clearSession, setIsEditorOpen, setSelectedNote, noteId]); + (async () => { + setIsLoading(true); + + await openSession(noteId); + setIsEditorOpen(true); + + setIsLoading(false); + })(); + }, [openSession, setIsEditorOpen, noteId]); return (