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
refactor: move vault logic to its own class
thecodrr5fae3128615d
diff --git a/apps/web/src/common/vault.js b/apps/web/src/common/vault.jsnew file mode 100644index 000000000..d090633fc--- /dev/null+++ b/apps/web/src/common/vault.js@@ -0,0 +1,20 @@+import { db } from "../common";+import { showPasswordDialog } from "../components/dialogs/passworddialog";++class Vault {+ static createVault() {+ return showPasswordDialog("create_vault", password =>+ db.vault.create(password)+ );+ }++ static unlockVault() {+ return showPasswordDialog("unlock_vault", password => {+ return db.vault+ .unlock(password)+ .then(() => true)+ .catch(() => false);+ });+ }+}+export default Vault;diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.jsindex fb1ceffa5..6218b70e0 100644--- a/apps/web/src/stores/note-store.js+++ b/apps/web/src/stores/note-store.js@@ -3,6 +3,7 @@ import createStore from "../common/store";import { store as editorStore } from "./editor-store";import { store as appStore } from "./app-store";import { showPasswordDialog } from "../components/dialogs/passworddialog";+import Vault from "../common/vault";function noteStore(set, get) {return {@@ -106,9 +107,9 @@ function noteStore(set, get) {.catch(async ({ message }) => {switch (message) {case "ERR_NO_VAULT":- return appStore.getState().createVault();+ return Vault.createVault();case "ERR_VAULT_LOCKED":- return appStore.getState().unlockVault();+ return Vault.unlockVault();default:return false;}