Skip to content

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

feat: add more dialogs to hashroutes

thecodrrf817711c5580
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index 930b4a21e..4ef7e91f1 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -12,7 +12,7 @@ import Editor from "./components/editor";
import useMobile from "./utils/use-mobile";
import GlobalMenuWrapper from "./components/globalmenuwrapper";
import { resetReminders } from "./common/reminders";
-import { isUserPremium } from "./common";
+import { db, isUserPremium } from "./common";
import { EV } from "notes-core/common";
import useTablet from "./utils/use-tablet";
import { showBuyDialog } from "./components/dialogs/buy-dialog";
@@ -36,6 +36,7 @@ function App() {
const initNotes = useNotesStore((store) => store.init);
const isEditorOpen = useStore((store) => store.isEditorOpen);
const toggleSideMenu = useStore((store) => store.toggleSideMenu);
+ const setIsVaultCreated = useStore((store) => store.setIsVaultCreated);
const isMobile = useMobile();
const isTablet = useTablet();
@@ -47,6 +48,7 @@ function App() {
initNotes();
(async function () {
await resetReminders();
+ setIsVaultCreated(await db.vault.exists());
})();
},
[refreshColors, refreshMenuPins, initUser, initNotes, addReminder]
diff --git a/apps/web/src/common/reminders.js b/apps/web/src/common/reminders.js
index 0ffdd1935..bba45b8b0 100644
--- a/apps/web/src/common/reminders.js
+++ b/apps/web/src/common/reminders.js
@@ -3,9 +3,9 @@ import { createBackup, db } from "./index";
import { store as appStore } from "../stores/app-store";
import * as Icon from "../components/icons";
import dayjs from "dayjs";
-import { showSignUpDialog } from "../components/dialogs/signupdialog";
import { showToast } from "../utils/toast";
import { showRecoveryKeyDialog } from "../components/dialogs/recoverykeydialog";
+import { hashNavigate } from "../navigation";
export async function shouldAddBackupReminder() {
const backupReminderOffset = Config.get("backupReminderOffset", 0);
@@ -42,7 +42,7 @@ export const Reminders = {
},
signup: {
title: "Sign up for cross-device syncing!",
- action: () => showSignUpDialog(),
+ action: () => hashNavigate("/signup"),
icon: Icon.Login,
},
email: {
diff --git a/apps/web/src/common/vault.js b/apps/web/src/common/vault.js
index d62de5c57..5b6e13d0d 100644
--- a/apps/web/src/common/vault.js
+++ b/apps/web/src/common/vault.js
@@ -3,8 +3,9 @@ import { showPasswordDialog } from "../components/dialogs/passworddialog";
import { showToast } from "../utils/toast";
class Vault {
- static createVault() {
- return showPasswordDialog("create_vault", async ({ password }) => {
+ static async createVault() {
+ if (await db.vault.exists()) return false;
+ return await showPasswordDialog("create_vault", async ({ password }) => {
await db.vault.create(password);
showToast("success", "Vault created.");
return true;
diff --git a/apps/web/src/components/dialogs/dialog.js b/apps/web/src/components/dialogs/dialog.js
index 985730d98..c13dd8837 100644
--- a/apps/web/src/components/dialogs/dialog.js
+++ b/apps/web/src/components/dialogs/dialog.js
@@ -145,7 +145,7 @@ export function showDialog(dialog) {
return new Promise((resolve) => {
const perform = (result) => {
ReactDOM.unmountComponentAtNode(root);
- hashNavigate("/");
+ hashNavigate("/", true);
resolve(result);
};
const PropDialog = dialog(perform);
diff --git a/apps/web/src/components/dialogs/logindialog.js b/apps/web/src/components/dialogs/logindialog.js
index dc79e5ae3..392aae593 100644
--- a/apps/web/src/components/dialogs/logindialog.js
+++ b/apps/web/src/components/dialogs/logindialog.js
@@ -7,6 +7,7 @@ import { useStore } from "../../stores/user-store";
import Field from "../field";
import { Checkbox, Label } from "@rebass/forms";
import { showForgotPasswordDialog } from "./forgotpassworddialog";
+import { hashNavigate } from "../../navigation";
const requiredValues = ["email", "password", "remember"];
function LoginDialog(props) {
@@ -66,7 +67,7 @@ function LoginDialog(props) {
variant="anchor"
sx={{ textAlign: "left" }}
fontSize="body"
- onClick={showSignUpDialog}
+ onClick={() => hashNavigate("/signup")}
>
Create an account here.
</Button>
diff --git a/apps/web/src/navigation/hash-routes.js b/apps/web/src/navigation/hash-routes.js
index 87bb29aee..861ceeb31 100644
--- a/apps/web/src/navigation/hash-routes.js
+++ b/apps/web/src/navigation/hash-routes.js
@@ -1,14 +1,16 @@
import React from "react";
+import Vault from "../common/vault";
import {
showAddNotebookDialog,
showEditNotebookDialog,
} from "../components/dialogs/addnotebookdialog";
import { closeOpenedDialog } from "../components/dialogs/dialog";
import { showLogInDialog } from "../components/dialogs/logindialog";
-import Editor from "../components/editor";
+import { showSignUpDialog } from "../components/dialogs/signupdialog";
import RouteContainer from "../components/route-container";
import SplitEditor from "../components/spliteditor";
import Unlock from "../components/unlock";
+import { store as appStore } from "../stores/app-store";
import { store as editorStore } from "../stores/editor-store";
import { store as noteStore } from "../stores/note-store";
import { isMobile } from "../utils/dimensions";
@@ -40,6 +42,17 @@ const hashroutes = {
"/notes/create": () => {
editorStore.newSession(noteStore.get().context);
},
+ "/signup": () => {
+ showSignUpDialog();
+ },
+ "/vault/changePassword": () => {
+ Vault.changeVaultPassword();
+ },
+ "/vault/create": () => {
+ Vault.createVault().then((res) => {
+ appStore.setIsVaultCreated(res);
+ });
+ },
"/login": () => {
showLogInDialog();
},
diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.js
index 21ff1cdea..e486a3298 100644
--- a/apps/web/src/stores/app-store.js
+++ b/apps/web/src/stores/app-store.js
@@ -16,6 +16,7 @@ class AppStore extends BaseStore {
isSideMenuOpen = !isMobile();
isFocusMode = false;
isEditorOpen = false;
+ isVaultCreated = false;
colors = [];
globalMenu = { items: [], data: {} };
reminders = [];
@@ -59,6 +60,10 @@ class AppStore extends BaseStore {
this.set((state) => (state.isEditorOpen = toggleState));
};
+ setIsVaultCreated = (toggleState) => {
+ this.set((state) => (state.isVaultCreated = toggleState));
+ };
+
/**
*
* @param {"backup"|"signup"|"email"|"recoverykey"} type
diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.js
index 8f4e860e9..e73468474 100644
--- a/apps/web/src/views/settings.js
+++ b/apps/web/src/views/settings.js
@@ -4,6 +4,7 @@ import * as Icon from "../components/icons";
import { useStore as useUserStore } from "../stores/user-store";
import { useStore as useThemeStore } from "../stores/theme-store";
import { useStore as useSettingStore } from "../stores/setting-store";
+import { useStore as useAppStore } from "../stores/app-store";
import AccentItem from "../components/accent-item";
import accents from "../theme/accents";
import { showLogInDialog } from "../components/dialogs/logindialog";
@@ -24,6 +25,7 @@ import ScrollContainer from "../components/scroll-container";
import { showLoadingDialog } from "../components/dialogs/loadingdialog";
import { showToast } from "../utils/toast";
import { showPasswordDialog } from "../components/dialogs/passworddialog";
+import { hashNavigate } from "../navigation";
function importBackup() {
return new Promise((resolve, reject) => {
@@ -55,6 +57,7 @@ function importBackup() {
function Settings(props) {
const isSystemThemeDark = useSystemTheme();
+ const isVaultCreated = useAppStore((store) => store.isVaultCreated);
const theme = useThemeStore((store) => store.theme);
const toggleNightMode = useThemeStore((store) => store.toggleNightMode);
const setTheme = useThemeStore((store) => store.setTheme);
@@ -72,7 +75,6 @@ function Settings(props) {
"backupReminderOffset",
0
);
- const [isVaultCreated, setIsVaultCreated] = useState(false);
const subscriptionDaysRemaining = useMemo(
() => dayjs(user?.subscription?.expiry).diff(dayjs(), "day") + 1,
@@ -88,12 +90,6 @@ function Settings(props) {
setTheme(isSystemThemeDark ? "dark" : "light");
}, [followSystemTheme, isSystemThemeDark, setTheme]);
- useEffect(() => {
- (async function () {
- setIsVaultCreated(await db.vault.exists());
- })();
- }, [isVaultCreated]);
-
return (
<ScrollContainer>
<Flex variant="columnFill" px={2}>
@@ -369,7 +365,10 @@ function Settings(props) {
{isVaultCreated ? (
<>
- <Button variant="list" onClick={Vault.changeVaultPassword}>
+ <Button
+ variant="list"
+ onClick={() => hashNavigate("/vault/changePassword")}
+ >
<TextWithTip text="Change vault password" />
</Button>
</>
@@ -377,7 +376,7 @@ function Settings(props) {
<Button
variant="list"
onClick={async () => {
- setIsVaultCreated(await Vault.createVault());
+ hashNavigate("/vault/create");
}}
>
<TextWithTip