Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: improve locking ux

thecodrr6866fff35c8d
diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.js
index deb6d757c..79e9062a5 100644
--- a/apps/web/src/stores/app-store.js
+++ b/apps/web/src/stores/app-store.js
@@ -55,21 +55,17 @@ function appStore(set, get) {
}
},
createVault: function() {
- return showPasswordDialog("create_vault").then(password => {
- if (!password) return false;
- return db.vault.create(password);
- });
+ return showPasswordDialog("create_vault", password =>
+ db.vault.create(password)
+ );
},
- unlockVault: function unlockVault() {
- return showPasswordDialog("unlock_vault")
- .then(password => {
- if (!password) return false;
- return db.vault.unlock(password);
- })
- .catch(({ message }) => {
- if (message === "ERR_WRNG_PWD") return unlockVault();
- else return false;
- });
+ unlockVault: function() {
+ return showPasswordDialog("unlock_vault", password => {
+ return db.vault
+ .unlock(password)
+ .then(() => true)
+ .catch(() => false);
+ });
}
};
}
diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js
index 3b1a99ead..42254981c 100644
--- a/apps/web/src/stores/editor-store.js
+++ b/apps/web/src/stores/editor-store.js
@@ -2,6 +2,7 @@ import createStore from "../common/store";
import { store as noteStore, LIST_TYPES } from "./note-store";
import { store as appStore } from "./app-store";
import { db } from "../common";
+import { showPasswordDialog } from "../components/dialogs/passworddialog";
const SESSION_STATES = {
stale: "stale",
@@ -42,10 +43,27 @@ function editorStore(set, get) {
},
openSession: async function(note) {
clearTimeout(get().session.timeout);
- const content = {
- text: note.content.text,
- delta: await db.notes.note(note).delta()
- };
+ let content = {};
+ if (!note.locked) {
+ content = {
+ text: note.content.text,
+ delta: await db.notes.note(note).delta()
+ };
+ } else {
+ const result = await showPasswordDialog("unlock_note", password => {
+ return db.vault
+ .open(note.id, password)
+ .then(note => {
+ content = note.content;
+ return true;
+ })
+ .catch(e => {
+ console.log(e);
+ return false;
+ });
+ });
+ if (!result) return;
+ }
noteStore.getState().setSelectedNote(note.id);
set(state => {
state.session = {
@@ -61,7 +79,7 @@ function editorStore(set, get) {
state: SESSION_STATES.new
};
});
- saveLastOpenedNote(note.id);
+ saveLastOpenedNote(!note.locked ? note.id : undefined);
},
saveSession: function(oldSession) {
set(state => {
diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.js
index 959b7a89a..81e5d2b11 100644
--- a/apps/web/src/stores/note-store.js
+++ b/apps/web/src/stores/note-store.js
@@ -88,25 +88,24 @@ function noteStore(set, get) {
if (index < 0) return;
}
state.notes.items[index].favorite = !note.favorite;
- syncEditor(note, "favorite");
});
+ syncEditor(note, "favorite");
get().refreshList(LIST_TYPES.fav);
},
- unlock: function unlock(note, index) {
- showPasswordDialog("unlock_note")
- .then(password => {
- if (!password) return;
- return db.vault.remove(note.id, password);
- })
- .then(() => {
+ unlock: function(note, index) {
+ showPasswordDialog("unlock_note", password => {
+ return db.vault
+ .remove(note.id, password)
+ .then(() => true)
+ .catch(() => false);
+ }).then(res => {
+ if (res) {
set(state => {
state.notes.items[index].locked = false;
});
- })
- .catch(({ message }) => {
- if (message === "ERR_WRNG_PWD") unlock(note, index);
- else console.log(message);
- });
+ syncEditor(note, "locked");
+ }
+ });
},
lock: function lock(note, index) {
db.vault
@@ -115,6 +114,7 @@ function noteStore(set, get) {
set(state => {
state.notes.items[index].locked = true;
});
+ syncEditor(note, "locked");
})
.catch(async ({ message }) => {
switch (message) {
diff --git a/apps/web/src/utils/theme.js b/apps/web/src/utils/theme.js
index 220892649..5990b06e6 100644
--- a/apps/web/src/utils/theme.js
+++ b/apps/web/src/utils/theme.js
@@ -95,6 +95,17 @@ const theme = (colors, shadows) => ({
outline: "none",
boxShadow: 4
}
+ },
+ error: {
+ variant: "forms.default",
+ borderColor: "red",
+ ":focus": {
+ outline: "none",
+ borderColor: "red"
+ },
+ ":hover": {
+ borderColor: "red"
+ }
}
},
text: {