A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: unlocking note keeps redirecting back
thecodrrc12f9cae025f
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.jsindex ae4875a0d..f6b9c8841 100644--- a/apps/web/src/components/note/index.js+++ b/apps/web/src/components/note/index.js@@ -141,6 +141,8 @@ function Note(props) {onClick={() => {if (note.conflicted) {hashNavigate(`/notes/${note.id}/conflict`, true);+ } else if (note.locked) {+ hashNavigate(`/notes/${note.id}/unlock`, true);} else {hashNavigate(`/notes/${note.id}/edit`, true);}diff --git a/apps/web/src/components/unlock/index.js b/apps/web/src/components/unlock/index.jsindex 669366992..64f242e98 100644--- a/apps/web/src/components/unlock/index.js+++ b/apps/web/src/components/unlock/index.js@@ -5,6 +5,7 @@ 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";function Unlock(props) {const { noteId } = props;@@ -12,6 +13,7 @@ function Unlock(props) {const [isWrong, setIsWrong] = useState(false);const openLockedSession = useEditorStore((store) => store.openLockedSession);const setIsEditorOpen = useAppStore((store) => store.setIsEditorOpen);+ const setSelectedNote = useNoteStore((store) => store.setSelectedNote);const submit = useCallback(async () => {const password = passwordRef.current.value;@@ -26,8 +28,9 @@ function Unlock(props) {}, [setIsWrong, noteId, openLockedSession]);useEffect(() => {+ setSelectedNote(noteId);setIsEditorOpen(true);- }, [setIsEditorOpen]);+ }, [setIsEditorOpen, setSelectedNote, noteId]);return (<Flex@@ -40,11 +43,11 @@ function Unlock(props) {<Flex justifyContent="center" alignItems="center"><Icon.Unlock size={"heading"} color="text" /><Text variant="heading" ml={2} fontSize={48}>- Unlock Note+ Open note</Text></Flex><Text variant="body" color="gray" textAlign="center">- Please unlock this note using your vault password.+ Please unlock your vault to open this note for editing.</Text><Inputref={passwordRef}diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex acf2c001d..ff9486870 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -12,6 +12,7 @@ const SESSION_STATES = {new: "new",locked: "locked",unlocked: "unlocked",+ opening: "opening",};const DEFAULT_SESSION = {notebooks: undefined,@@ -45,7 +46,9 @@ class EditorStore extends BaseStore {state.session = {...DEFAULT_SESSION,...note,+ id: undefined, // NOTE: we give a session id only after the note is opened.content: note.content,+ totalWords: state.session.totalWords,state: SESSION_STATES.unlocked,};});@@ -53,12 +56,21 @@ class EditorStore extends BaseStore {hashNavigate(`/notes/${note.id}/edit`, true);};+ _getNote = (note) => {+ const loadedNote = this.get().note;+ if (loadedNote) return loadedNote;+ return note.data;+ };+openSession = async (noteId) => {await db.notes.init();const session = this.get().session;- if (session.id === noteId && session.state === SESSION_STATES.unlocked) {- this.set((state) => (state.session.state = SESSION_STATES.new));+ if (session.state === SESSION_STATES.unlocked) {+ this.set((state) => {+ state.session.id = noteId;+ state.session.state = SESSION_STATES.new;+ });return;}@@ -74,6 +86,7 @@ class EditorStore extends BaseStore {let content = await db.content.raw(note.contentId);this.set((state) => {+ state.note = undefined;state.session = {...DEFAULT_SESSION,...note,