Skip to content

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

perf: code split dialogs

thecodrr5518e6461407
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index aa2561e52..294b9d7cb 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -18,7 +18,7 @@ import { resetReminders } from "./common/reminders";
import { db, isUserPremium } from "./common";
import { CHECK_IDS, EV, EVENTS } from "notes-core/common";
import useTablet from "./utils/use-tablet";
-import { showBuyDialog } from "./components/dialogs/buy-dialog";
+import { showBuyDialog } from "./common/dialog-controller";
import Banner from "./components/banner";
import StatusBar from "./components/statusbar";
import useRoutes from "./utils/use-routes";
@@ -30,7 +30,7 @@ import useVersion, { getCachedVersion } from "./utils/useVersion";
import {
showAppAvailableNotice,
showAppUpdatedNotice,
-} from "./components/dialogs/confirm";
+} from "./common/dialog-controller";
import { useAnimation } from "framer-motion";
import RouteContainer from "./components/route-container";
diff --git a/apps/web/src/common/dialogcontroller.js b/apps/web/src/common/dialogcontroller.js
new file mode 100644
index 000000000..8ec459e32
--- /dev/null
+++ b/apps/web/src/common/dialogcontroller.js
@@ -0,0 +1,440 @@
+import React from "react";
+import ReactDOM from "react-dom";
+import { hashNavigate } from "../navigation";
+import ThemeProvider from "../components/theme-provider";
+import { qclone } from "qclone";
+import { store as notebookStore } from "../stores/notebook-store";
+import { db } from ".";
+import { showToast } from "../utils/toast";
+import { CHECK_IDS } from "notes-core/common";
+import { Flex, Text } from "rebass";
+import * as Icon from "../components/icons";
+import download from "../utils/download";
+import { zip } from "../utils/zip";
+import Config from "../utils/config";
+
+function showDialog(dialog) {
+ const root = document.getElementById("dialogContainer");
+
+ if (root) {
+ return new Promise((resolve) => {
+ const perform = (result) => {
+ ReactDOM.unmountComponentAtNode(root);
+ hashNavigate("/", true);
+ resolve(result);
+ };
+ return import("../components/dialogs").then(({ default: Dialogs }) => {
+ const PropDialog = dialog(Dialogs, perform);
+ ReactDOM.render(<ThemeProvider>{PropDialog}</ThemeProvider>, root);
+ });
+ });
+ }
+ return Promise.reject("No element with id 'dialogContainer'");
+}
+
+export function closeOpenedDialog() {
+ const root = document.getElementById("dialogContainer");
+ ReactDOM.unmountComponentAtNode(root);
+}
+
+export function showEditNotebookDialog(notebookId) {
+ const notebook = db.notebooks.notebook(notebookId)?.data;
+ if (!notebook) return false;
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.AddNotebookDialog
+ isOpen={true}
+ notebook={notebook}
+ edit={true}
+ onDone={async (nb, deletedTopics) => {
+ // we remove the topics from notebook
+ // beforehand so we can add them manually, later
+ const topics = qclone(nb.topics);
+ delete nb.topics;
+
+ // add the edited notebook to db
+ await notebookStore.add({ ...notebook, ...nb });
+
+ // add or delete topics as required
+ const notebookTopics = db.notebooks.notebook(notebook.id).topics;
+ await notebookTopics.delete(...deletedTopics);
+ await notebookTopics.add(...topics);
+
+ showToast("success", "Notebook edited successfully!");
+ perform(true);
+ }}
+ onClose={() => {
+ perform(false);
+ }}
+ />
+ ));
+}
+
+export function showAddNotebookDialog() {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.AddNotebookDialog
+ isOpen={true}
+ onDone={async (nb) => {
+ // add the notebook to db
+ await notebookStore.add({ ...nb });
+
+ showToast("success", "Notebook added successfully!");
+ perform(true);
+ }}
+ onClose={() => {
+ perform(false);
+ }}
+ />
+ ));
+}
+
+const itemIdToIndex = {
+ sync: 0,
+ editor: 3,
+ backups: 5,
+ customize: 6,
+ discord: 7,
+ [CHECK_IDS.noteExport]: 4,
+ [CHECK_IDS.noteColor]: 1,
+ [CHECK_IDS.noteTag]: 1,
+ [CHECK_IDS.notebookAdd]: 1,
+ [CHECK_IDS.vaultAdd]: 2,
+ [CHECK_IDS.backupEncrypt]: 5,
+};
+export function showBuyDialog(initialItemId) {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.BuyDialog
+ initialIndex={itemIdToIndex[initialItemId]}
+ onCancel={() => perform(false)}
+ />
+ ));
+}
+
+export function confirm(
+ icon,
+ { title, subtitle, message, yesText, noText, yesAction }
+) {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.Confirm
+ title={title}
+ subtitle={subtitle}
+ message={message}
+ yesText={yesText}
+ noText={noText}
+ icon={icon}
+ onNo={() => perform(false)}
+ onYes={() => {
+ if (yesAction) yesAction();
+ perform(true);
+ }}
+ />
+ ));
+}
+
+export function showMultiDeleteConfirmation(type) {
+ let noun = type === "note" ? "Notes" : "Notebooks";
+
+ return confirm(Icon.Trash, {
+ title: `Delete these ${noun}?`,
+ message: (
+ <Text as="span">
+ These {type}s will be{" "}
+ <Text as="span" color="primary">
+ kept in your Trash for 7 days
+ </Text>{" "}
+ after which they will be permanently removed.
+ </Text>
+ ),
+ yesText: `Delete these ${type}s`,
+ noText: "Cancel",
+ });
+}
+
+export function showLogoutConfirmation() {
+ return confirm(Icon.Logout, {
+ title: `Logout?`,
+ message:
+ "Logging out will delete all local data and reset the app. Make sure you have synced your data before logging out.",
+ yesText: `Yes`,
+ noText: "No",
+ });
+}
+
+// export function showAccountDeletedNotice() {
+// return confirm(Icon.Logout, {
+// title: `Account deleted`,
+// message:
+// "You deleted your account from another device. You have been logged out.",
+// yesText: `Okay`,
+// });
+// }
+
+// export function showPasswordChangedNotice() {
+// return confirm(Icon.Logout, {
+// title: `Account password changed`,
+// message:
+// "Your account password was changed, please login again using the new password.",
+// yesText: `Okay`,
+// });
+// }
+
+export function showAccountLoggedOutNotice(reason) {
+ return confirm(Icon.Logout, {
+ title: reason,
+ message: `You were logged out`,
+ yesText: `Okay`,
+ });
+}
+
+export function showAppUpdatedNotice(version) {
+ return confirm(Icon.Update, {
+ title: `Welcome to v${version.formatted}`,
+ message: (
+ <Flex
+ flexDirection="column"
+ bg="bgSecondary"
+ p={1}
+ sx={{ borderRadius: "default" }}
+ >
+ <Text variant="title">Changelog:</Text>
+ <Text
+ as="pre"
+ overflow="auto"
+ fontFamily="monospace"
+ variant="body"
+ mt={1}
+ >
+ {version.changelog || "No change log."}
+ </Text>
+ </Flex>
+ ),
+ yesText: `Yay!`,
+ });
+}
+
+export function showAppAvailableNotice(version) {
+ return confirm(Icon.Update, {
+ title: `New version available`,
+ message: (
+ <Flex
+ flexDirection="column"
+ bg="bgSecondary"
+ p={1}
+ sx={{ borderRadius: "default" }}
+ >
+ <Text variant="title">v{version.formatted} changelog:</Text>
+ <Text
+ overflow="auto"
+ as="pre"
+ fontFamily="monospace"
+ variant="body"
+ mt={1}
+ sx={{ overflow: "auto" }}
+ >
+ {version.changelog || "No change log."}
+ </Text>
+ </Flex>
+ ),
+ yesText: `Update now`,
+ yesAction: () => window.location.reload(),
+ });
+}
+
+export function showEmailVerificationDialog() {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.EmailVerificationDialog onCancel={() => perform(false)} />
+ ));
+}
+
+export function showExportDialog(noteIds) {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.ExportDialog
+ title={
+ noteIds.length > 1 ? `Export ${noteIds.length} notes` : "Export note"
+ }
+ icon={Icon.Export}
+ onClose={() => perform(false)}
+ exportNote={async (format) => {
+ var files = [];
+ for (var noteId of noteIds) {
+ const note = db.notes.note(noteId);
+ const content = await note.export(format);
+ if (!content) continue;
+ files.push({ filename: note.title, content });
+ }
+ if (!files.length) return perform(false);
+ if (files.length === 1) {
+ download(files[0].filename, files[0].content, format);
+ } else {
+ const zipped = await zip(files, format);
+ download("notes", zipped, "zip");
+ }
+ perform(true);
+ }}
+ />
+ ));
+}
+
+export function showForgotPasswordDialog() {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.ForgotPasswordDialog onClose={() => perform()} />
+ ));
+}
+
+export function showLoadingDialog(dialogData) {
+ const { title, message, subtitle, action } = dialogData;
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.LoadingDialog
+ title={title}
+ subtitle={subtitle}
+ message={message}
+ action={action}
+ onDone={(e) => perform(e)}
+ />
+ ));
+}
+
+export const showLogInDialog = () => {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.LoginDialog onClose={() => perform()} />
+ ));
+};
+
+export function showMoveNoteDialog(noteIds) {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.MoveDialog
+ noteIds={noteIds}
+ onClose={() => perform(false)}
+ onMove={() => perform(true)}
+ />
+ ));
+}
+
+function getDialogData(type) {
+ switch (type) {
+ case "create_vault":
+ return {
+ title: "Create Your Vault",
+ subtitle: "A vault stores your notes in a password-encrypted storage.",
+ positiveButtonText: "Create vault",
+ };
+ case "unlock_vault":
+ return {
+ title: "Unlock your Vault",
+ subtitle: "Your vault will remain unlocked for 30 minutes.",
+ positiveButtonText: "Unlock vault",
+ };
+ case "unlock_note":
+ return {
+ title: "Unlock Note",
+ subtitle: "Unlocking will make this note openly available.",
+ positiveButtonText: "Unlock note",
+ };
+ case "change_password":
+ return {
+ title: "Change Vault Password",
+ subtitle:
+ "All locked notes will be re-encrypted with the new password.",
+ positiveButtonText: "Change password",
+ };
+ case "change_account_password":
+ return {
+ title: "Change Account Password",
+ subtitle:
+ "All your data will be re-encrypted and synced with the new password.",
+ positiveButtonText: "Change password",
+ };
+ case "delete_account":
+ return {
+ title: "Delete your account",
+ subtitle: (
+ <Text as="span" color="error">
+ All your data will be permanently deleted with{" "}
+ <b>no way of recovery</b>. Proceed with caution.
+ </Text>
+ ),
+ positiveButtonText: "Delete Account",
+ };
+ default:
+ return;
+ }
+}
+
+export function showPasswordDialog(type, validate) {
+ const { title, subtitle, positiveButtonText } = getDialogData(type);
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.PasswordDialog
+ type={type}
+ title={title}
+ subtitle={subtitle}
+ positiveButtonText={positiveButtonText}
+ validate={validate}
+ onClose={() => perform(false)}
+ onDone={() => perform(true)}
+ />
+ ));
+}
+
+export function showRecoveryKeyDialog() {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.RecoveryKeyDialog
+ onDone={() => {
+ Config.set("recoveryKeyBackupDate", Date.now());
+ perform(true);
+ }}
+ />
+ ));
+}
+
+export function showSignUpDialog() {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.SignUpDialog
+ onClose={async (res) => {
+ perform(res);
+ if (res === true) await showRecoveryKeyDialog();
+ }}
+ />
+ ));
+}
+
+export function showTopicDialog() {
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.TopicDialog
+ title={"Create a Topic"}
+ subtitle={"You can create as many topics as you want."}
+ icon={Icon.Topic}
+ onClose={() => {
+ perform(false);
+ }}
+ onAction={async (topic) => {
+ if (!topic) return;
+ const notebookId = notebookStore.get().selectedNotebookId;
+ await db.notebooks.notebook(notebookId).topics.add(topic);
+ notebookStore.setSelectedNotebook(notebookId);
+ perform(true);
+ }}
+ />
+ ));
+}
+
+export function showEditTopicDialog(notebookId, topicId) {
+ const topic = db.notebooks.notebook(notebookId)?.topics?.topic(topicId)
+ ?._topic;
+ if (!topic) return;
+ return showDialog((Dialogs, perform) => (
+ <Dialogs.TopicDialog
+ title={"Edit Topic"}
+ subtitle={`You are editing "${topic.title}" topic.`}
+ icon={Icon.Topic}
+ topic={topic}
+ onClose={() => perform(false)}
+ onAction={async (t) => {
+ await db.notebooks
+ .notebook(topic.notebookId)
+ .topics.add({ ...topic, title: t });
+ notebookStore.setSelectedNotebook(topic.notebookId);
+ showToast("success", "Topic edited successfully!");
+ perform(true);
+ }}
+ />
+ ));
+}
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index b6f00e7de..8be6c499b 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -6,7 +6,7 @@ import EventSource from "eventsource";
import { showToast } from "../utils/toast";
import download from "../utils/download";
import { Text } from "rebass";
-import { showLoadingDialog } from "../components/dialogs/loadingdialog";
+import { showLoadingDialog } from "../common/dialog-controller";
import Config from "../utils/config";
import { store as userstore } from "../stores/user-store";
import { hashNavigate } from "../navigation";
diff --git a/apps/web/src/common/list-profiles.js b/apps/web/src/common/list-profiles.js
index 920a268f5..346237fad 100644
--- a/apps/web/src/common/list-profiles.js
+++ b/apps/web/src/common/list-profiles.js
@@ -68,7 +68,7 @@ const TrashProfile = createProfile(
Math.max(MAX_HEIGHTS.note, MAX_HEIGHTS.notebook)
);
-export default {
+const Profiles = {
home: NotesProfile,
notebooks: NotebooksProfile,
notes: NotesProfile,
@@ -76,3 +76,4 @@ export default {
topics: TopicsProfile,
trash: TrashProfile,
};
+export default Profiles;
diff --git a/apps/web/src/common/reminders.js b/apps/web/src/common/reminders.js
index d22378a7a..8da36152c 100644
--- a/apps/web/src/common/reminders.js
+++ b/apps/web/src/common/reminders.js
@@ -3,7 +3,7 @@ import { createBackup, db } from "./index";
import { store as appStore } from "../stores/app-store";
import * as Icon from "../components/icons";
import dayjs from "dayjs";
-import { showRecoveryKeyDialog } from "../components/dialogs/recoverykeydialog";
+import { showRecoveryKeyDialog } from "../common/dialog-controller";
import { hashNavigate } from "../navigation";
export async function shouldAddBackupReminder() {
diff --git a/apps/web/src/common/selectionoptions.js b/apps/web/src/common/selectionoptions.js
index 2ce38e8ea..adc190e0d 100644
--- a/apps/web/src/common/selectionoptions.js
+++ b/apps/web/src/common/selectionoptions.js
@@ -5,9 +5,9 @@ import { store as nbStore } from "../stores/notebook-store";
import { store as editorStore } from "../stores/editor-store";
import { store as trashStore } from "../stores/trash-store";
import { db } from "./index";
-import { showMoveNoteDialog } from "../components/dialogs/movenotedialog";
-import { showMultiDeleteConfirmation } from "../components/dialogs/confirm";
-import { showExportDialog } from "../components/dialogs/exportdialog";
+import { showMoveNoteDialog } from "../common/dialog-controller";
+import { showMultiDeleteConfirmation } from "../common/dialog-controller";
+import { showExportDialog } from "../common/dialog-controller";
import { showToast } from "../utils/toast";
function createOption(key, icon, onClick) {
@@ -116,10 +116,11 @@ const TopicOptions = createOptions();
const TrashOptions = createOptions([RestoreOption]);
const FavoritesOptions = createOptions([UnfavoriteOption]);
-export default {
+const SelectionOptions = {
NotebooksOptions,
NotesOptions,
TopicOptions,
TrashOptions,
FavoritesOptions,
};
+export default SelectionOptions;
diff --git a/apps/web/src/common/vault.js b/apps/web/src/common/vault.js
index 5b6e13d0d..4ff59d71f 100644
--- a/apps/web/src/common/vault.js
+++ b/apps/web/src/common/vault.js
@@ -1,5 +1,5 @@
import { db } from "../common";
-import { showPasswordDialog } from "../components/dialogs/passworddialog";
+import { showPasswordDialog } from "../common/dialog-controller";
import { showToast } from "../utils/toast";
class Vault {
diff --git a/apps/web/src/components/accent-item/index.js b/apps/web/src/components/accent-item/index.js
index 0e09004e6..eab08832b 100644
--- a/apps/web/src/components/accent-item/index.js
+++ b/apps/web/src/components/accent-item/index.js
@@ -3,7 +3,7 @@ import { Flex } from "rebass";
import * as Icon from "../icons";
import { useStore as useThemeStore } from "../../stores/theme-store";
import { isUserPremium } from "../../common";
-import { showBuyDialog } from "../dialogs/buy-dialog";
+import { showBuyDialog } from "../../common/dialog-controller";
function AccentItem(props) {
const { code, label } = props;
diff --git a/apps/web/src/components/animated/index.js b/apps/web/src/components/animated/index.js
index 9f420c955..6ffd4f160 100644
--- a/apps/web/src/components/animated/index.js
+++ b/apps/web/src/components/animated/index.js
@@ -2,10 +2,11 @@ import { m as motion } from "framer-motion";
import { Flex, Box, Image, Text } from "rebass";
import { Input } from "@rebass/forms";
-export default {
+const Animated = {
Flex: motion.custom(Flex),
Box: motion.custom(Box),
Image: motion.custom(Image),
Text: motion.custom(Text),
Input: motion.custom(Input),
};
+export default Animated;
diff --git a/apps/web/src/components/dialogs/add-notebook-dialog.js b/apps/web/src/components/dialogs/add-notebook-dialog.js
index 9d343cf58..b887b6d5b 100644
--- a/apps/web/src/components/dialogs/add-notebook-dialog.js
+++ b/apps/web/src/components/dialogs/add-notebook-dialog.js
@@ -1,11 +1,8 @@
import React from "react";
import { Flex, Text } from "rebass";
import * as Icon from "../icons";
-import Dialog, { showDialog } from "./dialog";
-import { store } from "../../stores/notebook-store";
+import Dialog from "./dialog";
import { qclone } from "qclone";
-import { showToast } from "../../utils/toast";
-import { db } from "../../common";
import Field from "../field";
class AddNotebookDialog extends React.Component {
@@ -260,53 +257,3 @@ function TopicItem(props) {
</Flex>
);
}
-
-export function showEditNotebookDialog(notebookId) {
- const notebook = db.notebooks.notebook(notebookId)?.data;
- if (!notebook) return false;
- return showDialog((perform) => (
- <AddNotebookDialog
- isOpen={true}
- notebook={notebook}
- edit={true}
- onDone={async (nb, deletedTopics) => {
- // we remove the topics from notebook
- // beforehand so we can add them manually, later
- const topics = qclone(nb.topics);
- delete nb.topics;
-
- // add the edited notebook to db
- await store.add({ ...notebook, ...nb });
-
- // add or delete topics as required
- const notebookTopics = db.notebooks.notebook(notebook.id).topics;
- await notebookTopics.delete(...deletedTopics);
- await notebookTopics.add(...topics);
-
- showToast("success", "Notebook edited successfully!");
- perform(true);
- }}
- onClose={() => {
- perform(false);
- }}
- />
- ));
-}
-
-export function showAddNotebookDialog() {
- return showDialog((perform) => (
- <AddNotebookDialog
- isOpen={true}
- onDone={async (nb) => {
- // add the notebook to db
- await store.add({ ...nb });
-
- showToast("success", "Notebook added successfully!");
- perform(true);
- }}
- onClose={() => {
- perform(false);
- }}
- />
- ));
-}
diff --git a/apps/web/src/components/dialogs/buydialog.js b/apps/web/src/components/dialogs/buydialog.js
index 329ee33d0..686d85f43 100644
--- a/apps/web/src/components/dialogs/buydialog.js
+++ b/apps/web/src/components/dialogs/buydialog.js
@@ -1,11 +1,11 @@
-import React, { useEffect, useState } from "react";
+import React from "react";
import { Text, Flex, Button } from "rebass";
-import Dialog, { showDialog } from "./dialog";
+import Dialog from "./dialog";
import * as Icon from "../icons";
import { useStore as useUserStore } from "../../stores/user-store";
import { useStore as useThemeStore } from "../../stores/theme-store";
import { upgrade } from "../../common/upgrade";
-import { showSignUpDialog } from "./signupdialog";
+import { showSignUpDialog } from "../../common/dialog-controller";
import { ReactComponent as Personalization } from "../../assets/accent.svg";
import { ReactComponent as Backups } from "../../assets/backup.svg";
import { ReactComponent as Export } from "../../assets/export.svg";
@@ -16,21 +16,7 @@ import { ReactComponent as Vault } from "../../assets/vault.svg";
import "react-responsive-carousel/lib/styles/carousel.min.css"; // requires a loader
import { Carousel } from "react-responsive-carousel";
import { changeSvgTheme } from "../../utils/css";
-import { CHECK_IDS } from "notes-core/common";
-const itemIdToIndex = {
- sync: 0,
- editor: 3,
- backups: 5,
- customize: 6,
- discord: 7,
- [CHECK_IDS.noteExport]: 4,
- [CHECK_IDS.noteColor]: 1,
- [CHECK_IDS.noteTag]: 1,
- [CHECK_IDS.notebookAdd]: 1,
- [CHECK_IDS.vaultAdd]: 2,
- [CHECK_IDS.backupEncrypt]: 5,
-};
const premiumDetails = [
{
title: "Automatic syncing",
@@ -232,12 +218,4 @@ function BuyDialog(props) {
</Dialog>
);
}
-
-export function showBuyDialog(initialItemId) {
- return showDialog((perform) => (
- <BuyDialog
- initialIndex={itemIdToIndex[initialItemId]}
- onCancel={() => perform(false)}
- />
- ));
-}
+export default BuyDialog;
diff --git a/apps/web/src/components/dialogs/confirm.js b/apps/web/src/components/dialogs/confirm.js
index b8dc0ab46..1c89e44f4 100644
--- a/apps/web/src/components/dialogs/confirm.js
+++ b/apps/web/src/components/dialogs/confirm.js
@@ -1,7 +1,6 @@
import React from "react";
-import { Box, Flex, Text } from "rebass";
-import Dialog, { showDialog } from "./dialog";
-import * as Icon from "../icons";
+import { Box, Text } from "rebass";
+import Dialog from "./dialog";
function Confirm(props) {
return (
@@ -29,132 +28,4 @@ function Confirm(props) {
);
}
-export function confirm(
- icon,
- { title, subtitle, message, yesText, noText, yesAction }
-) {
- return showDialog((perform) => (
- <Confirm
- title={title}
- subtitle={subtitle}
- message={message}
- yesText={yesText}
- noText={noText}
- icon={icon}
- onNo={() => perform(false)}
- onYes={() => {
- if (yesAction) yesAction();
- perform(true);
- }}
- />
- ));
-}
-
-export function showMultiDeleteConfirmation(type) {
- let noun = type === "note" ? "Notes" : "Notebooks";
-
- return confirm(Icon.Trash, {
- title: `Delete these ${noun}?`,
- message: (
- <Text as="span">
- These {type}s will be{" "}
- <Text as="span" color="primary">
- kept in your Trash for 7 days
- </Text>{" "}
- after which they will be permanently removed.
- </Text>
- ),
- yesText: `Delete these ${type}s`,
- noText: "Cancel",
- });
-}
-
-export function showLogoutConfirmation() {
- return confirm(Icon.Logout, {
- title: `Logout?`,
- message:
- "Logging out will delete all local data and reset the app. Make sure you have synced your data before logging out.",
- yesText: `Yes`,
- noText: "No",
- });
-}
-
-// export function showAccountDeletedNotice() {
-// return confirm(Icon.Logout, {
-// title: `Account deleted`,
-// message:
-// "You deleted your account from another device. You have been logged out.",
-// yesText: `Okay`,
-// });
-// }
-
-// export function showPasswordChangedNotice() {
-// return confirm(Icon.Logout, {
-// title: `Account password changed`,
-// message:
-// "Your account password was changed, please login again using the new password.",
-// yesText: `Okay`,
-// });
-// }
-
-export function showAccountLoggedOutNotice(reason) {
- return confirm(Icon.Logout, {
- title: reason,
- message: `You were logged out`,
- yesText: `Okay`,
- });
-}
-
-export function showAppUpdatedNotice(version) {
- return confirm(Icon.Update, {
- title: `Welcome to v${version.formatted}`,
- message: (
- <Flex
- flexDirection="column"
- bg="bgSecondary"
- p={1}
- sx={{ borderRadius: "default" }}
- >
- <Text variant="title">Changelog:</Text>
- <Text
- as="pre"
- overflow="auto"
- fontFamily="monospace"
- variant="body"
- mt={1}
- >
- {version.changelog || "No change log."}
- </Text>
- </Flex>
- ),
- yesText: `Yay!`,
- });
-}
-
-export function showAppAvailableNotice(version) {
- return confirm(Icon.Update, {
- title: `New version available`,
- message: (
- <Flex
- flexDirection="column"
- bg="bgSecondary"
- p={1}
- sx={{ borderRadius: "default" }}
- >
- <Text variant="title">v{version.formatted} changelog:</Text>
- <Text
- overflow="auto"
- as="pre"
- fontFamily="monospace"
- variant="body"
- mt={1}
- sx={{ overflow: "auto" }}
- >
- {version.changelog || "No change log."}
- </Text>
- </Flex>
- ),
- yesText: `Update now`,
- yesAction: () => window.location.reload(),
- });
-}
+export default Confirm;
diff --git a/apps/web/src/components/dialogs/dialog.js b/apps/web/src/components/dialogs/dialog.js
index 4dd6e8ba8..7f3a222ea 100644
--- a/apps/web/src/components/dialogs/dialog.js
+++ b/apps/web/src/components/dialogs/dialog.js
@@ -1,11 +1,8 @@
import React from "react";
-import ReactDOM from "react-dom";
import { Flex, Text, Button as RebassButton } from "rebass";
-import ThemeProvider from "../theme-provider";
import * as Icon from "../icons";
import Modal from "react-modal";
import { useTheme } from "emotion-theming";
-import { hashNavigate } from "../../navigation";
function Dialog(props) {
const theme = useTheme();
@@ -139,25 +136,3 @@ function Dialog(props) {
}
export default Dialog;
-
-export function showDialog(dialog) {
- const root = document.getElementById("dialogContainer");
-
- if (root) {
- return new Promise((resolve) => {
- const perform = (result) => {
- ReactDOM.unmountComponentAtNode(root);
- hashNavigate("/", true);
- resolve(result);
- };
- const PropDialog = dialog(perform);
- ReactDOM.render(<ThemeProvider>{PropDialog}</ThemeProvider>, root);
- });
- }
- return Promise.reject("No element with id 'dialogContainer'");
-}
-
-export function closeOpenedDialog() {
- const root = document.getElementById("dialogContainer");
- ReactDOM.unmountComponentAtNode(root);
-}
diff --git a/apps/web/src/components/dialogs/email-verification-dialog.js b/apps/web/src/components/dialogs/email-verification-dialog.js
index 886b7423a..d0fefe3f9 100644
--- a/apps/web/src/components/dialogs/email-verification-dialog.js
+++ b/apps/web/src/components/dialogs/email-verification-dialog.js
@@ -1,6 +1,6 @@
import React from "react";
import { Flex, Button, Text } from "rebass";
-import Dialog, { showDialog } from "./dialog";
+import Dialog from "./dialog";
import { useStore as useUserStore } from "../../stores/user-store";
import { db } from "../../common";
import { useState } from "react";
@@ -73,9 +73,4 @@ function EmailVerificationDialog(props) {
</Dialog>
);
}
-
-export function showEmailVerificationDialog() {
- return showDialog((perform) => (
- <EmailVerificationDialog onCancel={() => perform(false)} />
- ));
-}
+export default EmailVerificationDialog;
diff --git a/apps/web/src/components/dialogs/exportdialog.js b/apps/web/src/components/dialogs/exportdialog.js
index 1f9813a15..682f3bcf9 100644
--- a/apps/web/src/components/dialogs/exportdialog.js
+++ b/apps/web/src/components/dialogs/exportdialog.js
@@ -1,10 +1,7 @@
import React from "react";
import { Flex, Button, Text } from "rebass";
-import { db } from "../../common";
-import download from "../../utils/download";
-import { zip } from "../../utils/zip";
import * as Icon from "../icons";
-import Dialog, { showDialog } from "./dialog";
+import Dialog from "./dialog";
const formats = [
{
@@ -71,32 +68,4 @@ function ExportDialog(props) {
</Dialog>
);
}
-
-export function showExportDialog(noteIds) {
- return showDialog((perform) => (
- <ExportDialog
- title={
- noteIds.length > 1 ? `Export ${noteIds.length} notes` : "Export note"
- }
- icon={Icon.Export}
- onClose={() => perform(false)}
- exportNote={async (format) => {
- var files = [];
- for (var noteId of noteIds) {
- const note = db.notes.note(noteId);
- const content = await note.export(format);
- if (!content) continue;
- files.push({ filename: note.title, content });
- }
- if (!files.length) return perform(false);
- if (files.length === 1) {
- download(files[0].filename, files[0].content, format);
- } else {
- const zipped = await zip(files, format);
- download("notes", zipped, "zip");
- }
- perform(true);
- }}
- />
- ));
-}
+export default ExportDialog;
diff --git a/apps/web/src/components/dialogs/forgotpassworddialog.js b/apps/web/src/components/dialogs/forgotpassworddialog.js
index 8514a63c5..b6df65edb 100644
--- a/apps/web/src/components/dialogs/forgotpassworddialog.js
+++ b/apps/web/src/components/dialogs/forgotpassworddialog.js
@@ -1,6 +1,6 @@
import React, { useState } from "react";
import { Text, Box } from "rebass";
-import Dialog, { showDialog } from "./dialog";
+import Dialog from "./dialog";
import Field from "../field";
import { db } from "../../common";
import { showToast } from "../../utils/toast";
@@ -71,9 +71,4 @@ function ForgotPasswordDialog(props) {
</Dialog>
);
}
-
-export function showForgotPasswordDialog() {
- return showDialog((perform) => (
- <ForgotPasswordDialog onClose={() => perform()} />
- ));
-}
+export default ForgotPasswordDialog;
diff --git a/apps/web/src/components/dialogs/index.js b/apps/web/src/components/dialogs/index.js
new file mode 100644
index 000000000..ff3024973
--- /dev/null
+++ b/apps/web/src/components/dialogs/index.js
@@ -0,0 +1,30 @@
+import AddNotebookDialog from "./addnotebookdialog";
+import BuyDialog from "./buy-dialog";
+import Confirm from "./confirm";
+import EmailVerificationDialog from "./emailverificationdialog";
+import ExportDialog from "./exportdialog";
+import ForgotPasswordDialog from "./forgotpassworddialog";
+import LoadingDialog from "./loadingdialog";
+import LoginDialog from "./logindialog";
+import MoveDialog from "./movenotedialog";
+import PasswordDialog from "./passworddialog";
+import RecoveryKeyDialog from "./recoverykeydialog";
+import SignUpDialog from "./signupdialog";
+import TopicDialog from "./topicdialog";
+
+const Dialogs = {
+ AddNotebookDialog,
+ BuyDialog,
+ Confirm,
+ EmailVerificationDialog,
+ ExportDialog,
+ ForgotPasswordDialog,
+ LoadingDialog,
+ LoginDialog,
+ MoveDialog,
+ PasswordDialog,
+ RecoveryKeyDialog,
+ SignUpDialog,
+ TopicDialog,
+};
+export default Dialogs;
diff --git a/apps/web/src/components/dialogs/loading-dialog.js b/apps/web/src/components/dialogs/loading-dialog.js
index 05a76ac6c..e84a2c794 100644
--- a/apps/web/src/components/dialogs/loading-dialog.js
+++ b/apps/web/src/components/dialogs/loading-dialog.js
@@ -1,6 +1,6 @@
import React, { useEffect } from "react";
import { Box, Text } from "rebass";
-import Dialog, { showDialog } from "./dialog";
+import Dialog from "./dialog";
import * as Icon from "../icons";
function LoadingDialog(props) {
@@ -30,16 +30,4 @@ function LoadingDialog(props) {
</Dialog>
);
}
-
-export function showLoadingDialog(dialogData) {
- const { title, message, subtitle, action } = dialogData;
- return showDialog((perform) => (
- <LoadingDialog
- title={title}
- subtitle={subtitle}
- message={message}
- action={action}
- onDone={(e) => perform(e)}
- />
- ));
-}
+export default LoadingDialog;
diff --git a/apps/web/src/components/dialogs/logindialog.js b/apps/web/src/components/dialogs/logindialog.js
index 3f19de5b7..8e4bd7004 100644
--- a/apps/web/src/components/dialogs/logindialog.js
+++ b/apps/web/src/components/dialogs/logindialog.js
@@ -1,11 +1,11 @@
import React, { useEffect, useState } from "react";
import { Flex, Button, Text } from "rebass";
import * as Icon from "../icons";
-import Dialog, { showDialog } from "./dialog";
+import Dialog from "./dialog";
import { useStore } from "../../stores/user-store";
import Field from "../field";
import { Checkbox, Label } from "@rebass/forms";
-import { showForgotPasswordDialog } from "./forgotpassworddialog";
+import { showForgotPasswordDialog } from "../../common/dialog-controller";
import { hashNavigate } from "../../navigation";
const requiredValues = ["email", "password", "remember"];
@@ -163,7 +163,4 @@ function LoginDialog(props) {
</Dialog>
);
}
-
-export const showLogInDialog = () => {
- return showDialog((perform) => <LoginDialog onClose={() => perform()} />);
-};
+export default LoginDialog;
diff --git a/apps/web/src/components/dialogs/move-note-dialog.js b/apps/web/src/components/dialogs/move-note-dialog.js
index e4157a066..2e4883356 100644
--- a/apps/web/src/components/dialogs/move-note-dialog.js
+++ b/apps/web/src/components/dialogs/move-note-dialog.js
@@ -2,7 +2,7 @@ import React from "react";
import { Flex, Box, Text } from "rebass";
import * as Icon from "../icons";
import { db } from "../../common";
-import Dialog, { showDialog } from "./dialog";
+import Dialog from "./dialog";
import { showNotesMovedToast } from "../../common/toasts";
import { showToast } from "../../utils/toast";
import Field from "../field";
@@ -199,16 +199,7 @@ class MoveDialog extends React.Component {
);
}
}
-
-export function showMoveNoteDialog(noteIds) {
- return showDialog((perform) => (
- <MoveDialog
- noteIds={noteIds}
- onClose={() => perform(false)}
- onMove={() => perform(true)}
- />
- ));
-}
+export default MoveDialog;
function Item(props) {
const { icon: Icon, indent = 0, title, totalNotes, onClick, action } = props;
diff --git a/apps/web/src/components/dialogs/password-dialog.js b/apps/web/src/components/dialogs/password-dialog.js
index ed868b662..de54a87fd 100644
--- a/apps/web/src/components/dialogs/password-dialog.js
+++ b/apps/web/src/components/dialogs/password-dialog.js
@@ -1,6 +1,6 @@
import React, { useState, useCallback, useMemo } from "react";
import { Box, Text } from "rebass";
-import Dialog, { showDialog } from "./dialog";
+import Dialog from "./dialog";
import Field from "../field";
const requiredValues = ["password", "newPassword", "oldPassword"];
@@ -97,68 +97,4 @@ function PasswordDialog(props) {
</Dialog>
);
}
-
-function getDialogData(type) {
- switch (type) {
- case "create_vault":
- return {
- title: "Create Your Vault",
- subtitle: "A vault stores your notes in a password-encrypted storage.",
- positiveButtonText: "Create vault",
- };
- case "unlock_vault":
- return {
- title: "Unlock your Vault",
- subtitle: "Your vault will remain unlocked for 30 minutes.",
- positiveButtonText: "Unlock vault",
- };
- case "unlock_note":
- return {
- title: "Unlock Note",
- subtitle: "Unlocking will make this note openly available.",
- positiveButtonText: "Unlock note",
- };
- case "change_password":
- return {
- title: "Change Vault Password",
- subtitle:
- "All locked notes will be re-encrypted with the new password.",
- positiveButtonText: "Change password",
- };
- case "change_account_password":
- return {
- title: "Change Account Password",
- subtitle:
- "All your data will be re-encrypted and synced with the new password.",
- positiveButtonText: "Change password",
- };
- case "delete_account":
- return {
- title: "Delete your account",
- subtitle: (
- <Text as="span" color="error">
- All your data will be permanently deleted with{" "}
- <b>no way of recovery</b>. Proceed with caution.
- </Text>
- ),
- positiveButtonText: "Delete Account",
- };
- default:
- return;
- }
-}
-
-export function showPasswordDialog(type, validate) {
- const { title, subtitle, positiveButtonText } = getDialogData(type);
- return showDialog((perform) => (
- <PasswordDialog
- type={type}
- title={title}
- subtitle={subtitle}
- positiveButtonText={positiveButtonText}
- validate={validate}
- onClose={() => perform(false)}
- onDone={() => perform(true)}
- />
- ));
-}
+export default PasswordDialog;
diff --git a/apps/web/src/components/dialogs/recovery-key-dialog.js b/apps/web/src/components/dialogs/recovery-key-dialog.js
index 1e58f9035..205ce8c1c 100644
--- a/apps/web/src/components/dialogs/recovery-key-dialog.js
+++ b/apps/web/src/components/dialogs/recovery-key-dialog.js
@@ -1,11 +1,10 @@
import React, { useEffect, useState } from "react";
import { Text, Flex, Button } from "rebass";
-import Dialog, { showDialog } from "./dialog";
+import Dialog from "./dialog";
import { db } from "../../common";
import Logo from "../../assets/notesnook-small.png";
import download from "../../utils/download";
import ClipboardJS from "clipboard";
-import Config from "../../utils/config";
import { captureMessage } from "@sentry/react";
import { useStore as useUserStore } from "../../stores/user-store";
import { Suspense } from "react";
@@ -32,7 +31,7 @@ function RecoveryKeyDialog(props) {
}, 2000);
e.clearSelection();
});
- clipboard.on("error", function (e) {
+ clipboard.on("error", function () {
captureMessage("Error while copying text.");
});
return () => {
@@ -123,14 +122,4 @@ function RecoveryKeyDialog(props) {
</Dialog>
);
}
-
-export function showRecoveryKeyDialog() {
- return showDialog((perform) => (
- <RecoveryKeyDialog
- onDone={() => {
- Config.set("recoveryKeyBackupDate", Date.now());
- perform(true);
- }}
- />
- ));
-}
+export default RecoveryKeyDialog;
diff --git a/apps/web/src/components/dialogs/signupdialog.js b/apps/web/src/components/dialogs/signupdialog.js
index 156f98efa..5577b2d35 100644
--- a/apps/web/src/components/dialogs/signupdialog.js
+++ b/apps/web/src/components/dialogs/signupdialog.js
@@ -1,11 +1,10 @@
import React, { useState } from "react";
import { Text, Box, Button, Flex } from "rebass";
import * as Icon from "../icons";
-import Dialog, { showDialog } from "./dialog";
+import Dialog from "./dialog";
import { useStore } from "../../stores/user-store";
-import { showLogInDialog } from "./logindialog";
+import { showLogInDialog } from "../../common/dialog-controller";
import Field from "../field";
-import { showRecoveryKeyDialog } from "./recoverykeydialog";
const requiredValues = ["email", "password"];
function SignUpDialog(props) {
@@ -95,14 +94,4 @@ function SignUpDialog(props) {
</Dialog>
);
}
-
-export function showSignUpDialog() {
- return showDialog((perform) => (
- <SignUpDialog
- onClose={async (res) => {
- perform(res);
- if (res === true) await showRecoveryKeyDialog();
- }}
- />
- ));
-}
+export default SignUpDialog;
diff --git a/apps/web/src/components/dialogs/topicdialog.js b/apps/web/src/components/dialogs/topicdialog.js
index 31ebaf7ee..9a5b7235b 100644
--- a/apps/web/src/components/dialogs/topicdialog.js
+++ b/apps/web/src/components/dialogs/topicdialog.js
@@ -1,11 +1,7 @@
import React, { useRef } from "react";
import { Box } from "rebass";
import { Input } from "@rebass/forms";
-import * as Icon from "../icons";
-import { db } from "../../common";
-import Dialog, { showDialog } from "./dialog";
-import { store } from "../../stores/notebook-store";
-import { showToast } from "../../utils/toast";
+import Dialog from "./dialog";
function TopicDialog(props) {
const ref = useRef();
@@ -37,45 +33,4 @@ function TopicDialog(props) {
);
}
-export function showTopicDialog() {
- return showDialog((perform) => (
- <TopicDialog
- title={"Create a Topic"}
- subtitle={"You can create as many topics as you want."}
- icon={Icon.Topic}
- onClose={() => {
- perform(false);
- }}
- onAction={async (topic) => {
- if (!topic) return;
- const notebookId = store.get().selectedNotebookId;
- await db.notebooks.notebook(notebookId).topics.add(topic);
- store.setSelectedNotebook(notebookId);
- perform(true);
- }}
- />
- ));
-}
-
-export function showEditTopicDialog(notebookId, topicId) {
- const topic = db.notebooks.notebook(notebookId)?.topics?.topic(topicId)
- ?._topic;
- if (!topic) return;
- return showDialog((perform) => (
- <TopicDialog
- title={"Edit Topic"}
- subtitle={`You are editing "${topic.title}" topic.`}
- icon={Icon.Topic}
- topic={topic}
- onClose={() => perform(false)}
- onAction={async (t) => {
- await db.notebooks
- .notebook(topic.notebookId)
- .topics.add({ ...topic, title: t });
- store.setSelectedNotebook(topic.notebookId);
- showToast("success", "Topic edited successfully!");
- perform(true);
- }}
- />
- ));
-}
+export default TopicDialog;
diff --git a/apps/web/src/components/editor/editormenu.js b/apps/web/src/components/editor/editormenu.js
index 66906b40c..32af92d15 100644
--- a/apps/web/src/components/editor/editormenu.js
+++ b/apps/web/src/components/editor/editormenu.js
@@ -1,7 +1,7 @@
import React from "react";
import { useStore } from "../../stores/editor-store";
import { Flex, Button } from "rebass";
-import { showExportDialog } from "../dialogs/exportdialog";
+import { showExportDialog } from "../../common/dialog-controller";
function EditorMenu(props) {
const saveSession = useStore((store) => store.saveSession);
diff --git a/apps/web/src/components/editor/tinymce.js b/apps/web/src/components/editor/tinymce.js
index ce84b9d0b..9246ee6b4 100644
--- a/apps/web/src/components/editor/tinymce.js
+++ b/apps/web/src/components/editor/tinymce.js
@@ -25,7 +25,7 @@ import "./plugins/quickimage";
import "./editor.css";
import { Editor } from "@tinymce/tinymce-react";
import { isUserPremium } from "../../common";
-import { showBuyDialog } from "../dialogs/buy-dialog";
+import { showBuyDialog } from "../../common/dialog-controller";
import { useStore as useThemeStore } from "../../stores/theme-store";
const markdownPatterns = [
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index eaff3633f..f0970c75b 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -3,13 +3,13 @@ import { Flex, Text } from "rebass";
import * as Icon from "../icons";
import TimeAgo from "timeago-react";
import ListItem from "../list-item";
-import { showMoveNoteDialog } from "../dialogs/movenotedialog";
+import { showMoveNoteDialog } from "../../common/dialog-controller";
import { store, useStore } from "../../stores/note-store";
-import { showPasswordDialog } from "../dialogs/passworddialog";
+import { showPasswordDialog } from "../../common/dialog-controller";
import { db, COLORS } from "../../common";
import { useTheme } from "emotion-theming";
import Colors from "../menu/colors";
-import { showExportDialog } from "../dialogs/exportdialog";
+import { showExportDialog } from "../../common/dialog-controller";
import { showItemDeletedToast } from "../../common/toasts";
import { showUnpinnedToast } from "../../common/toasts";
import { showToast } from "../../utils/toast";
diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.js
index b6c3ddbe7..aa1a8a7ac 100644
--- a/apps/web/src/components/properties/index.js
+++ b/apps/web/src/components/properties/index.js
@@ -9,7 +9,7 @@ import { useStore as useAppStore } from "../../stores/app-store";
import Animated from "../animated";
import Toggle from "./toggle";
import { toTitleCase } from "../../utils/string";
-import { showMoveNoteDialog } from "../dialogs/movenotedialog";
+import { showMoveNoteDialog } from "../../common/dialog-controller";
import { navigate } from "../../navigation";
const tools = [
diff --git a/apps/web/src/components/status-bar/index.js b/apps/web/src/components/status-bar/index.js
index e1f4c3644..2eed2787c 100644
--- a/apps/web/src/components/status-bar/index.js
+++ b/apps/web/src/components/status-bar/index.js
@@ -3,7 +3,7 @@ import { Button, Flex, Text } from "rebass";
import EditorFooter from "../editor/footer";
import * as Icon from "../icons";
import { useStore as useUserStore } from "../../stores/user-store";
-import { showLogInDialog } from "../dialogs/logindialog";
+import { showLogInDialog } from "../../common/dialog-controller";
import TimeAgo from "timeago-react";
import { hashNavigate, navigate } from "../../navigation";
diff --git a/apps/web/src/components/trash-item/index.js b/apps/web/src/components/trash-item/index.js
index c9e29c66b..2f678a42d 100644
--- a/apps/web/src/components/trash-item/index.js
+++ b/apps/web/src/components/trash-item/index.js
@@ -1,6 +1,6 @@
import React from "react";
import ListItem from "../list-item";
-import { confirm } from "../dialogs/confirm";
+import { confirm } from "../../common/dialog-controller";
import * as Icon from "../icons";
import { store } from "../../stores/trash-store";
import { Flex, Text } from "rebass";
diff --git a/apps/web/src/interfaces/storage.js b/apps/web/src/interfaces/storage.js
index dc5ea1c63..ffa2f8684 100644
--- a/apps/web/src/interfaces/storage.js
+++ b/apps/web/src/interfaces/storage.js
@@ -64,7 +64,7 @@ async function getCryptoKey(name) {
}
}
-export default {
+const Storage = {
read,
readMulti,
write,
@@ -77,6 +77,7 @@ export default {
encrypt: crypto.encrypt,
decrypt: crypto.decrypt,
};
+export default Storage;
let enc = new TextEncoder();
let dec = new TextDecoder();
diff --git a/apps/web/src/navigation/hash-routes.js b/apps/web/src/navigation/hash-routes.js
index 25de5d8b7..f2478a9c0 100644
--- a/apps/web/src/navigation/hash-routes.js
+++ b/apps/web/src/navigation/hash-routes.js
@@ -1,13 +1,13 @@
import React from "react";
import Vault from "../common/vault";
-import { showEmailVerificationDialog } from "../components/dialogs/emailverificationdialog";
+import { showEmailVerificationDialog } from "../common/dialog-controller";
import {
showAddNotebookDialog,
showEditNotebookDialog,
-} from "../components/dialogs/addnotebookdialog";
-import { closeOpenedDialog } from "../components/dialogs/dialog";
-import { showLogInDialog } from "../components/dialogs/logindialog";
-import { showSignUpDialog } from "../components/dialogs/signupdialog";
+} from "../common/dialog-controller";
+import { closeOpenedDialog } from "../common/dialog-controller";
+import { showLogInDialog } from "../common/dialog-controller";
+import { showSignUpDialog } from "../common/dialog-controller";
import RouteContainer from "../components/route-container";
import SplitEditor from "../components/spliteditor";
import Unlock from "../components/unlock";
@@ -18,7 +18,7 @@ import { isMobile, isTablet } from "../utils/dimensions";
import {
showEditTopicDialog,
showTopicDialog,
-} from "../components/dialogs/topicdialog";
+} from "../common/dialog-controller";
import { hashNavigate } from ".";
const hashroutes = {
diff --git a/apps/web/src/stores/notebook-store.js b/apps/web/src/stores/notebook-store.js
index 8978cd6d6..bfc4cacf1 100644
--- a/apps/web/src/stores/notebook-store.js
+++ b/apps/web/src/stores/notebook-store.js
@@ -1,6 +1,5 @@
import { db } from "../common/index";
import createStore from "../common/store";
-import { store as trashStore } from "./trash-store";
import { store as appStore } from "./app-store";
import BaseStore from "./index";
import { showToast } from "../utils/toast";
diff --git a/apps/web/src/stores/user-store.js b/apps/web/src/stores/user-store.js
index 8ff43f912..8bd072e45 100644
--- a/apps/web/src/stores/user-store.js
+++ b/apps/web/src/stores/user-store.js
@@ -5,10 +5,10 @@ import { store as appStore } from "./app-store";
import BaseStore from "./index";
import config from "../utils/config";
import { EV, EVENTS } from "notes-core/common";
-import { showLoadingDialog } from "../components/dialogs/loadingdialog";
+import { showLoadingDialog } from "../common/dialog-controller";
import { Text } from "rebass";
import { showToast } from "../utils/toast";
-import { showAccountLoggedOutNotice } from "../components/dialogs/confirm";
+import { showAccountLoggedOutNotice } from "../common/dialog-controller";
class UserStore extends BaseStore {
isLoggedIn = false;
diff --git a/apps/web/src/utils/config.js b/apps/web/src/utils/config.js
index 89756de62..2c1991c62 100644
--- a/apps/web/src/utils/config.js
+++ b/apps/web/src/utils/config.js
@@ -15,4 +15,5 @@ function clear() {
window.localStorage.clear();
}
-export default { set, get, clear };
+const Config = { set, get, clear };
+export default Config;
diff --git a/apps/web/src/utils/use-mobile.js b/apps/web/src/utils/use-mobile.js
index e92861c5f..790a270a5 100644
--- a/apps/web/src/utils/use-mobile.js
+++ b/apps/web/src/utils/use-mobile.js
@@ -1,3 +1,4 @@
import useMediaQuery from "./use-media-query";
-export default () => useMediaQuery("(max-width: 480px)");
+const useMobile = () => useMediaQuery("(max-width: 480px)");
+export default useMobile;
diff --git a/apps/web/src/utils/use-system-theme.js b/apps/web/src/utils/use-system-theme.js
index 75207a8f4..bdd58e0be 100644
--- a/apps/web/src/utils/use-system-theme.js
+++ b/apps/web/src/utils/use-system-theme.js
@@ -1,3 +1,4 @@
import useMediaQuery from "./use-media-query";
-export default () => useMediaQuery("(prefers-color-scheme: dark)");
+const useSystemTheme = () => useMediaQuery("(prefers-color-scheme: dark)");
+export default useSystemTheme;
diff --git a/apps/web/src/utils/use-tablet.js b/apps/web/src/utils/use-tablet.js
index 87302cd5e..7a9c302f9 100644
--- a/apps/web/src/utils/use-tablet.js
+++ b/apps/web/src/utils/use-tablet.js
@@ -1,4 +1,5 @@
import useMediaQuery from "./use-media-query";
-export default () =>
+const useTablet = () =>
useMediaQuery("(min-width: 480px) and (max-width: 1000px)");
+export default useTablet;
diff --git a/apps/web/src/utils/useVersion.js b/apps/web/src/utils/useVersion.js
index f3873f635..f20bced21 100644
--- a/apps/web/src/utils/useVersion.js
+++ b/apps/web/src/utils/useVersion.js
@@ -13,7 +13,7 @@ var APP_VERSION = {
var CACHED_VERSION = undefined;
-export default () => {
+function useVersion() {
const [version, setVersion] = useState(APP_VERSION);
useEffect(() => {
@@ -24,7 +24,8 @@ export default () => {
}, []);
return version;
-};
+}
+export default useVersion;
/**
*
diff --git a/apps/web/src/views/home.js b/apps/web/src/views/home.js
index 94ba627ce..623c6cf7e 100644
--- a/apps/web/src/views/home.js
+++ b/apps/web/src/views/home.js
@@ -4,7 +4,6 @@ import ListContainer from "../components/list-container";
import NotesPlaceholder from "../components/placeholders/notesplacholder";
import { db } from "../common";
import { hashNavigate } from "../navigation";
-import { Profiler } from "react";
function Home() {
const notes = useStore((store) => store.notes);
diff --git a/apps/web/src/views/notebooks.js b/apps/web/src/views/notebooks.js
index f4efe4932..6e5ca3e69 100644
--- a/apps/web/src/views/notebooks.js
+++ b/apps/web/src/views/notebooks.js
@@ -1,4 +1,4 @@
-import React, { useEffect } from "react";
+import React from "react";
import ListContainer from "../components/list-container";
import { useStore, store } from "../stores/notebook-store";
import NotebooksPlaceholder from "../components/placeholders/notebooks-placeholder";
diff --git a/apps/web/src/views/search.js b/apps/web/src/views/search.js
index 5d74acfb5..00f6c5315 100644
--- a/apps/web/src/views/search.js
+++ b/apps/web/src/views/search.js
@@ -1,7 +1,6 @@
import React, { useState } from "react";
import ListContainer from "../components/list-container";
import SearchPlaceholder from "../components/placeholders/search-placeholder";
-import { useQueryParams } from "../navigation";
import { db, notesFromContext } from "../common";
import SearchBox from "../components/search";
import ProgressBar from "../components/progress-bar";
diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.js
index c8a9842d9..5837a21a3 100644
--- a/apps/web/src/views/settings.js
+++ b/apps/web/src/views/settings.js
@@ -7,8 +7,8 @@ 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";
-import { showLogoutConfirmation } from "../components/dialogs/confirm";
+import { showLogInDialog } from "../common/dialog-controller";
+import { showLogoutConfirmation } from "../common/dialog-controller";
import useSystemTheme from "../utils/use-system-theme";
import {
createBackup,
@@ -18,12 +18,12 @@ import {
} from "../common";
import { usePersistentState } from "../utils/hooks";
import dayjs from "dayjs";
-import { showRecoveryKeyDialog } from "../components/dialogs/recoverykeydialog";
-import { showBuyDialog } from "../components/dialogs/buy-dialog";
+import { showRecoveryKeyDialog } from "../common/dialog-controller";
+import { showBuyDialog } from "../common/dialog-controller";
import ScrollContainer from "../components/scroll-container";
-import { showLoadingDialog } from "../components/dialogs/loadingdialog";
+import { showLoadingDialog } from "../common/dialog-controller";
import { showToast } from "../utils/toast";
-import { showPasswordDialog } from "../components/dialogs/passworddialog";
+import { showPasswordDialog } from "../common/dialog-controller";
import { hashNavigate } from "../navigation";
import useVersion from "../utils/useVersion";
import http from "notes-core/utils/http";
diff --git a/apps/web/src/views/trash.js b/apps/web/src/views/trash.js
index 893d3cedc..ed97cb75e 100644
--- a/apps/web/src/views/trash.js
+++ b/apps/web/src/views/trash.js
@@ -1,7 +1,7 @@
-import React, { useEffect } from "react";
+import React from "react";
import * as Icon from "../components/icons";
import ListContainer from "../components/list-container";
-import { confirm } from "../components/dialogs/confirm";
+import { confirm } from "../common/dialog-controller";
import { useStore, store } from "../stores/trash-store";
import TrashPlaceholder from "../components/placeholders/trash-placeholder";
import { showToast } from "../utils/toast";