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: locking note does not update UI
thecodrr5701f226ef7b
diff --git a/apps/web/src/common/vault.js b/apps/web/src/common/vault.jsindex bce8f1aeb..556d9d394 100644--- a/apps/web/src/common/vault.js+++ b/apps/web/src/common/vault.js@@ -17,33 +17,37 @@ class Vault {});}- static unlockNote(id, done) {- return showPasswordDialog("unlock_note", (password) => {- return db.vault- .remove(id, password)- .then(() => true)- .catch((e) => {- if (e.message === db.vault.ERRORS.wrongPassword) return false;- else console.error(e);- });- }).then((res) => res && done());+ static unlockNote(id) {+ return new Promise((resolve) => {+ return showPasswordDialog("unlock_note", (password) => {+ return db.vault+ .remove(id, password)+ .then(() => true)+ .catch((e) => {+ if (e.message === db.vault.ERRORS.wrongPassword) return false;+ else console.error(e);+ });+ }).then(resolve);+ });}- static lockNote(id, done) {- return db.vault- .add(id)- .then(done)- .catch(({ message }) => {- switch (message) {- case db.vault.ERRORS.noVault:- return Vault.createVault();- case db.vault.ERRORS.vaultLocked:- return Vault.unlockVault();- default:- return false;- }- })- .then((result) => result && Vault.lockNote(id));+ static lockNote(id) {+ return new Promise(function lock(resolve) {+ db.vault+ .add(id)+ .then(resolve)+ .catch(({ message }) => {+ switch (message) {+ case db.vault.ERRORS.noVault:+ return Vault.createVault();+ case db.vault.ERRORS.vaultLocked:+ return Vault.unlockVault();+ default:+ return false;+ }+ })+ .then((result) => result && lock(resolve));+ });}}export default Vault;diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.jsindex 96504753a..fe4df9bc5 100644--- a/apps/web/src/components/note/index.js+++ b/apps/web/src/components/note/index.js@@ -52,7 +52,7 @@ function menuItems(note, context) {{title: note.locked ? "Unlock" : "Lock",onClick: async () => {- const { unlock, lock } = store;+ const { unlock, lock } = store.get();if (!note.locked) {await lock(note.id);showToast("success", "Note locked successfully!");diff --git a/apps/web/src/components/unlock/index.js b/apps/web/src/components/unlock/index.jsindex 04cacffe1..50510ae65 100644--- a/apps/web/src/components/unlock/index.js+++ b/apps/web/src/components/unlock/index.js@@ -1,15 +1,18 @@-import React, { useRef, useState, useCallback } from "react";+import React, { useRef, useState, useCallback, useEffect } from "react";import { Flex, Text, Button } from "rebass";import { Input } from "@rebass/forms";import * as Icon from "../icons";import { db } from "../../common";import { useStore as useEditorStore } from "../../stores/editor-store";+import { navigate } from "hookrouter";+import { setHashParam } from "../../utils/useHashParam";function Unlock(props) {const { noteId } = props;const passwordRef = useRef();const [isWrong, setIsWrong] = useState(false);const openLockedSession = useEditorStore((store) => store.openLockedSession);+ const clearSession = useEditorStore((store) => store.clearSession);const submit = useCallback(async () => {const password = passwordRef.current.value;diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex e1fea2265..768848139 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -48,8 +48,8 @@ class EditorStore extends BaseStore {openLastSession = async () => {// Do not reopen last session on mobileif (isMobile()) return;-const id = localStorage.getItem("lastOpenedNote");+if (id) {setHashParam({ note: id });}diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.jsindex 59fdf2718..34ebd0b8e 100644--- a/apps/web/src/stores/note-store.js+++ b/apps/web/src/stores/note-store.js@@ -77,11 +77,19 @@ class NoteStore extends BaseStore {};unlock = async (id) => {- await Vault.unlockNote(id, () => this._setValue(id, "locked", false));+ await Vault.unlockNote(id).then(async () => {+ if (editorStore.get().session.id === id)+ await editorStore.openSession(id);+ this.refresh();+ });};lock = async (id) => {- await Vault.lockNote(id, () => this._setValue(id, "locked", true));+ await Vault.lockNote(id).then(async () => {+ if (editorStore.get().session.id === id)+ await editorStore.openSession(id);+ this.refresh();+ });};setColor = async (id, color) => {@@ -116,8 +124,10 @@ class NoteStore extends BaseStore {*/_syncEditor = (noteId, action, value) => {const { session, setSession } = editorStore.get();+ console.log(session.id, noteId, session.id !== noteId);if (session.id !== noteId) return false;setSession((state) => (state.session[action] = value), true);+ return true;};}