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(editor): add full screen for unlocking note
thecodrra211d2c89972
diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex 9b236280e..5fc82e5dd 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -72,10 +72,9 @@ function App() {variant="columnFill"/></Animated.Flex>- <Flex- width={[show ? 0 : "100%", 0, "100%"]}- className="EditorNavigator"- />+ <Flex width={[show ? 0 : "100%", 0, "100%"]}>+ <NavigationContainer navigator={EditorNavigator} />+ </Flex></Flex><Box id="dialogContainer" /><Box id="snackbarContainer" />diff --git a/apps/web/src/common/vault.js b/apps/web/src/common/vault.jsindex 08f5f769d..bce8f1aeb 100644--- a/apps/web/src/common/vault.js+++ b/apps/web/src/common/vault.js@@ -29,23 +29,6 @@ class Vault {}).then((res) => res && done());}- static openNote(id) {- return new Promise((resolve) => {- showPasswordDialog("unlock_note", (password) => {- return db.vault- .open(id, password)- .then((note) => {- resolve(note.content);- return true;- })- .catch((e) => {- if (e.message === db.vault.ERRORS.wrongPassword) return false;- else console.error(e);- });- });- });- }-static lockNote(id, done) {return db.vault.add(id)diff --git a/apps/web/src/components/unlock/index.js b/apps/web/src/components/unlock/index.jsnew file mode 100644index 000000000..82df5f5cc--- /dev/null+++ b/apps/web/src/components/unlock/index.js@@ -0,0 +1,81 @@+import React, { useRef, useState, useCallback } from "react";+import { Flex, Text, Button } from "rebass";+import { Input } from "@rebass/forms";+import * as Icon from "../icons";+import { db } from "../../common";++function Unlock(props) {+ const { id, onDone } = props;+ const passwordRef = useRef();+ const [isWrong, setIsWrong] = useState(false);+ const submit = useCallback(async () => {+ const password = passwordRef.current.value;+ try {+ const note = await db.vault.open(id, password);+ onDone(note.content);+ } catch (e) {+ if (e.message === db.vault.ERRORS.wrongPassword) {+ setIsWrong(true);+ }+ }+ }, [setIsWrong, id, onDone]);++ return (+ <Flex+ width={["0%", "0%", "100%"]}+ flex="1 1 auto"+ justifyContent="center"+ alignItems="center"+ >+ <Flex flexDirection="column" width="30%" alignItems="center">+ <Flex justifyContent="center" alignItems="center">+ <Icon.Unlock size={48} color="text" />+ <Text variant="heading" ml={2} fontSize={48}>+ Unlock Note+ </Text>+ </Flex>+ <Text variant="body" color="gray">+ Please unlock this note using your vault password.+ </Text>+ <Input+ ref={passwordRef}+ autoFocus+ variant={isWrong ? "error" : "input"}+ mt={5}+ placeholder="Enter vault password"+ type="password"+ onKeyUp={async (e) => {+ if (e.key === "Enter") {+ await submit();+ } else {+ setIsWrong(false);+ }+ }}+ />+ {isWrong && (+ <Flex+ alignItems="center"+ justifyContent="center"+ alignSelf="flex-start"+ color="error"+ mt={2}+ >+ <Icon.Alert color="error" />+ <Text ml={1} fontSize={"body"}>+ Wrong password+ </Text>+ </Flex>+ )}+ <Button+ mt={3}+ onClick={async () => {+ await submit();+ }}+ >+ Unlock+ </Button>+ </Flex>+ </Flex>+ );+}+export default Unlock;diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex b3eace400..f847cf07b 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -5,7 +5,6 @@ import { store as tagStore } from "./tag-store";import { store as mergeStore } from "./mergestore";import { db } from "../common";import BaseStore from ".";-import Vault from "../common/vault.js";import EditorNavigator from "../navigation/navigators/editornavigator";import { isMobile } from "../utils/dimensions";@@ -52,10 +51,11 @@ class EditorStore extends BaseStore {if (note.conflicted) {return await mergeStore.openConflict(note);- } else {- EditorNavigator.navigate("editor");}+ noteStore.setSelectedNote(note.id);+ saveLastOpenedNote(note.id);+let content = {};if (!note.locked) {content = {@@ -63,7 +63,10 @@ class EditorStore extends BaseStore {delta: await db.notes.note(note).delta(),};} else {- content = await Vault.openNote(note.id);+ content = await EditorNavigator.navigateWithResult("unlock", {+ id: note.id,+ });+ console.log(content);if (!content) return;}@@ -75,10 +78,8 @@ class EditorStore extends BaseStore {state: SESSION_STATES.new,};});- noteStore.setSelectedNote(note.id);- if (note.locked) return;- saveLastOpenedNote(note.id);+ EditorNavigator.navigate("editor");};saveSession = (oldSession) => {