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
feat: enable locked note opening
thecodrrb2db840ffaf2
diff --git a/apps/web/package.json b/apps/web/package.jsonindex a74d5d794..7d025ba4f 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -71,4 +71,4 @@"last 4 edge version"]}-}\ No newline at end of file+}diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.jsindex a3e4f218b..e58a5ab35 100644--- a/apps/web/src/components/editor/index.js+++ b/apps/web/src/components/editor/index.js@@ -11,6 +11,7 @@ import EditorMenu from "./editormenu";import Header from "./header";import { useHashParam } from "../../utils/useHashParam";import SplitEditor from "../spliteditor";+import Unlock from "../unlock";function Editor() {const delta = useStore((store) => store.session.content.delta);@@ -27,6 +28,7 @@ function Editor() {const quillRef = useRef();const [diff] = useHashParam("diff");+ const [unlock] = useHashParam("unlock");useEffect(() => {// move the toolbar outside (easiest way)@@ -42,6 +44,7 @@ function Editor() {}, [init]);useEffect(() => {+ if (!quillRef || !quillRef.current) return;if (sessionState === SESSION_STATES.new) {const { quill } = quillRef.current;quill.setContents(delta, "init");@@ -50,8 +53,9 @@ function Editor() {const text = quill.getText();quill.setSelection(text.length, 0, "init");}- }, [sessionState, delta]);+ }, [sessionState, delta, quillRef]);+ if (unlock) return <Unlock noteId={unlock} />;if (diff) return <SplitEditor diffId={diff} />;return (<Animated.Flexdiff --git a/apps/web/src/components/unlock/index.js b/apps/web/src/components/unlock/index.jsindex 82df5f5cc..04cacffe1 100644--- a/apps/web/src/components/unlock/index.js+++ b/apps/web/src/components/unlock/index.js@@ -3,22 +3,25 @@ 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";function Unlock(props) {- const { id, onDone } = props;+ const { noteId } = props;const passwordRef = useRef();const [isWrong, setIsWrong] = useState(false);+ const openLockedSession = useEditorStore((store) => store.openLockedSession);+const submit = useCallback(async () => {const password = passwordRef.current.value;try {- const note = await db.vault.open(id, password);- onDone(note.content);+ const note = await db.vault.open(noteId, password);+ openLockedSession(note);} catch (e) {if (e.message === db.vault.ERRORS.wrongPassword) {setIsWrong(true);}}- }, [setIsWrong, id, onDone]);+ }, [setIsWrong, noteId, openLockedSession]);return (<Flexdiff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex 4f11a1186..29a5dcf88 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -50,33 +50,38 @@ class EditorStore extends BaseStore {}};+ openLockedSession = async (note) => {+ setHashParam({});+ setHashParam({ note: note.id }, false);+ saveLastOpenedNote(note.id);+ this.set((state) => {+ state.session = {+ ...DEFAULT_SESSION,+ ...note,+ content: note.content,+ state: SESSION_STATES.new,+ };+ });+ };+openSession = async (noteId) => {let note = db.notes.note(noteId);if (!note) return;note = note.data;-clearTimeout(this.get().session.timeout);noteStore.setSelectedNote(note.id);- if (note.conflicted) {- setHashParam({ diff: noteId });- return;- }++ if (note.locked) return setHashParam({ unlock: noteId });+ if (note.conflicted) return setHashParam({ diff: noteId });+saveLastOpenedNote(note.id);let content = {};- if (!note.locked) {- content = {- text: await db.notes.note(note).text(),- delta: await db.notes.note(note).delta(),- };- } else {- /* content = await EditorNavigator.navigateWithResult("unlock", {- id: note.id,- });- console.log(content);- if (!content) return; */- }+ content = {+ text: await db.notes.note(note).text(),+ delta: await db.notes.note(note).delta(),+ };this.set((state) => {state.session = {diff --git a/apps/web/yarn.lock b/apps/web/yarn.lockindex f475bde8e..f650f99c4 100644--- a/apps/web/yarn.lock+++ b/apps/web/yarn.lock@@ -7638,7 +7638,7 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":version "1.5.0"- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#207f498c66896e680abeffae7efdcf83dbcf9b43"+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#fa55c0d6732cdfda5108a4e77071dc9e3cb89e70"dependencies:fast-sort "^2.0.1"fuzzysearch "^1.0.3"