Skip to content

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

feat: improve dialogs ui/ux

thecodrr8345d35629d6
diff --git a/apps/web/__e2e__/notebooks.test.js b/apps/web/__e2e__/notebooks.test.js
index 234dddc78..85e553a07 100644
--- a/apps/web/__e2e__/notebooks.test.js
+++ b/apps/web/__e2e__/notebooks.test.js
@@ -11,7 +11,7 @@ const {
} = require("./utils/actions");
const List = require("./utils/listitemidbuilder");
const Menu = require("./utils/menuitemidbuilder");
-const { checkNotePresence, isAbsent, isPresent } = require("./utils/conditions");
+const { checkNotePresence, isPresent } = require("./utils/conditions");
beforeEach(async () => {
page = await browser.newPage();
@@ -27,11 +27,8 @@ async function fillNotebookDialog(notebook) {
for (let i = 0; i < notebook.topics.length; ++i) {
let topic = notebook.topics[i];
-
- await page.fill(getTestId(`dialog-topic-name-${i}`), topic);
-
- if (!(await page.$(getTestId(`dialog-topic-name-${i + 1}`))))
- await page.click(getTestId("dialog-add-topic"));
+ await page.fill(getTestId(`dialog-nb-topic`), topic);
+ await page.click(getTestId("dialog-nb-topic-action"));
}
await page.click(getTestId("dialog-yes"));
@@ -103,9 +100,7 @@ async function deleteNotebookAndCheckAbsence(notebookSelector) {
await page.waitForTimeout(500);
- await expect(
- page.$(notebookSelector)
- ).resolves.toBeFalsy();
+ await expect(page.$(notebookSelector)).resolves.toBeFalsy();
await navigateTo("trash");
@@ -141,17 +136,31 @@ test("edit a notebook", async () => {
await useContextMenu(notebookSelector, () => clickMenuItem("edit"));
- const editedNotebook = {
+ const notebook = {
title: "An Edited Notebook",
description: "A new edited description",
topics: ["Topic 1", "Topic 2", "Topic 3", "Topic 4", "Topic 5"],
};
- await fillNotebookDialog(editedNotebook);
+ await page.fill(getTestId("dialog-nb-name"), notebook.title);
+
+ await page.fill(getTestId("dialog-nb-description"), notebook.description);
+
+ for (var i = 1; i <= notebook.topics.length; ++i) {
+ let id = getTestId(`dialog-nb-topic-${i}-actions-edit`);
+ let topic = notebook.topics[i - 1];
+ if ((await page.$(id)) !== null) {
+ await page.click(id);
+ }
+ await page.fill(getTestId("dialog-nb-topic"), topic);
+ await page.click(getTestId("dialog-nb-topic-action"));
+ }
+
+ await confirmDialog();
await page.waitForTimeout(1000);
- await checkNotebookPresence(editedNotebook);
+ await checkNotebookPresence(notebook);
});
test("edit topics individually", async () => {
@@ -165,7 +174,7 @@ test("edit topics individually", async () => {
await page.click(Menu.new("menuitem").item("edit").build());
const editedTopicTitle = "Topic " + index + " edit 1";
- await page.fill(getTestId("edit-topic-dialog"), editedTopicTitle);
+ await page.fill(getTestId("dialog-edit-topic"), editedTopicTitle);
await page.click(getTestId("dialog-yes"));
@@ -201,7 +210,7 @@ test("permanently delete a notebook", async () => {
).resolves.toBeFalsy();
});
-test.only("pin a notebook", async () => {
+test("pin a notebook", async () => {
const notebookSelector = await createNotebookAndCheckPresence();
await useContextMenu(notebookSelector, () => clickMenuItem("pin"));
@@ -209,7 +218,11 @@ test.only("pin a notebook", async () => {
// wait for the menu to properly close
await page.waitForTimeout(500);
- await useContextMenu(notebookSelector, () => expect(isPresent(Menu.new("menuitem").item("unpin").build())).resolves.toBeTruthy());
+ await useContextMenu(notebookSelector, () =>
+ expect(
+ isPresent(Menu.new("menuitem").item("unpin").build())
+ ).resolves.toBeTruthy()
+ );
// wait for the menu to properly close
await page.waitForTimeout(500);
diff --git a/apps/web/src/common/upgrade.js b/apps/web/src/common/upgrade.js
index 77d858818..c8a2c87e8 100644
--- a/apps/web/src/common/upgrade.js
+++ b/apps/web/src/common/upgrade.js
@@ -1,16 +1,27 @@
-function loadTCheckout(document, src, libName, config) {
+function loadTCheckout() {
return new Promise((resolve) => {
+ const config = {
+ app: { merchant: "250327951921", iframeLoad: "checkout" },
+ cart: {
+ host: "https://secure.2checkout.com",
+ customization: "inline",
+ },
+ };
var script = document.createElement("script");
- script.src = src;
+ script.src =
+ "https://secure.avangate.com/checkout/client/twoCoInlineCart.js";
script.async = true;
var firstScriptElement = document.getElementsByTagName("script")[0];
script.onload = function () {
for (var namespace in config) {
if (config.hasOwnProperty(namespace)) {
- window[libName].setup.setConfig(namespace, config[namespace]);
+ window["TwoCoInlineCart"].setup.setConfig(
+ namespace,
+ config[namespace]
+ );
}
}
- window[libName].register();
+ window["TwoCoInlineCart"].register();
resolve();
};
@@ -19,19 +30,8 @@ function loadTCheckout(document, src, libName, config) {
}
async function upgrade(user) {
- if (!("TwoCoInlineCart" in window)) {
- await loadTCheckout(
- document,
- "https://secure.avangate.com/checkout/client/twoCoInlineCart.js",
- "TwoCoInlineCart",
- {
- app: { merchant: "250327951921", iframeLoad: "checkout" },
- cart: {
- host: "https://secure.2checkout.com",
- customization: "inline",
- },
- }
- );
+ if (!window.TwoCoInlineCart) {
+ await loadTCheckout();
}
const { TwoCoInlineCart: cart } = window;
diff --git a/apps/web/src/components/dialogs/add-notebook-dialog.js b/apps/web/src/components/dialogs/add-notebook-dialog.js
index 1a7802050..7797ff50b 100644
--- a/apps/web/src/components/dialogs/add-notebook-dialog.js
+++ b/apps/web/src/components/dialogs/add-notebook-dialog.js
@@ -1,5 +1,5 @@
import React from "react";
-import { Flex, Box, Button as RebassButton } from "rebass";
+import { Flex, Box, Button as RebassButton, Text } from "rebass";
import { Input } from "@rebass/forms";
import * as Icon from "../icons";
import Dialog, { showDialog } from "./dialog";
@@ -9,44 +9,50 @@ import { showToast } from "../../utils/toast";
import { db } from "../../common";
class AddNotebookDialog extends React.Component {
- MAX_AVAILABLE_HEIGHT = window.innerHeight * 0.3;
title = "";
description = "";
- _inputRefs = [];
- lastLength = 0;
- topics = [{ title: "" }];
id = undefined;
+ deletedTopics = [];
state = {
- topics: [{ title: "" }],
- focusedInputIndex: 0,
+ topics: [],
+ isEditting: false,
+ editIndex: -1,
};
- performActionOnTopic(index) {
- if (this.state.focusedInputIndex !== index) {
- this.removeTopic(index);
- } else {
- this.addTopic(index);
+ removeTopic(index) {
+ const topics = this.state.topics.slice();
+ if (topics[index].id) {
+ this.deletedTopics.push(topics[index].id);
}
+ topics.splice(index, 1);
+ this.setState({
+ topics,
+ });
}
- removeTopic(index) {
- this._action(index, 1);
+ addTopic(topicTitle) {
+ const topics = this.state.topics.slice();
+ topics.push({ title: topicTitle });
+ this.setState({
+ topics,
+ });
+ this.resetTopicInput();
}
- addTopic(index) {
- this._action(index + 1, 0, { title: "" });
+ editTopic(index) {
+ this._topicInputRef.value = this.state.topics[index].title;
+ this._topicInputRef.focus();
+ this.setState({ isEditting: true, editIndex: index });
}
- _action(index, deleteCount, replaceItem) {
- if (replaceItem !== undefined)
- this.topics.splice(index, deleteCount, replaceItem);
- else this.topics.splice(index, deleteCount);
+ doneEditingTopic() {
+ this.setState({ isEditting: false, editIndex: -1 });
+ this.resetTopicInput();
+ }
- this.setState({ topics: this.topics }, () =>
- setTimeout(() => {
- this._inputRefs[index].focus();
- }, 0)
- );
+ resetTopicInput() {
+ this._topicInputRef.value = "";
+ this._topicInputRef.focus();
}
UNSAFE_componentWillReceiveProps(nextProps) {
@@ -58,26 +64,22 @@ class AddNotebookDialog extends React.Component {
componentDidMount() {
if (!this.props.notebook) return;
const { title, description, id, topics } = qclone(this.props.notebook);
- console.log(topics);
- this.topics = topics;
this.setState({
topics,
});
this.title = title;
+ this.notebookTitle = title;
this.description = description;
this.id = id;
}
_reset() {
this.title = "";
+ this.notebookTitle = "";
this.description = "";
- this._inputRefs = [];
- this.lastLength = 0;
- this.topics = [{ title: "" }];
this.id = undefined;
this.setState({
- topics: [{ title: "" }],
- focusedInputIndex: 0,
+ topics: [],
});
}
@@ -86,28 +88,34 @@ class AddNotebookDialog extends React.Component {
return (
<Dialog
isOpen={props.isOpen}
- title={props.edit ? "Edit this Notebook" : "Create a Notebook"}
+ title={props.edit ? "Edit Notebook" : "Create a Notebook"}
description={
- props.edit ? "" : "Notebooks are the best way to organize your notes."
+ props.edit
+ ? `You are editing "${this.notebookTitle}".`
+ : "Notebooks are the best way to organize your notes."
}
icon={Icon.Notebook}
positiveButton={{
- text: "Create notebook",
+ text: props.edit ? "Edit notebook" : "Create notebook",
onClick: () => {
- props.onDone({
- title: this.title,
- description: this.description,
- topics: this.topics.map((topic) => {
- if (topic.id) return topic;
- return topic.title;
- }),
- id: this.id,
- });
+ props.onDone(
+ {
+ title: this.title,
+ description: this.description,
+ topics: this.state.topics.map((topic) => {
+ if (topic.id) return topic;
+ return topic.title;
+ }),
+ id: this.id,
+ },
+ this.deletedTopics
+ );
},
}}
- negativeButton={{ text: "Cancel", onClick: props.close }}
+ onClose={props.onClose}
+ negativeButton={{ text: "Cancel", onClick: props.onClose }}
>
- <Box>
+ <Flex flexDirection="column" sx={{ overflowY: "auto" }}>
<Input
data-test-id="dialog-nb-name"
autoFocus
@@ -117,79 +125,70 @@ class AddNotebookDialog extends React.Component {
/>
<Input
data-test-id="dialog-nb-description"
- sx={{ marginTop: 2 }}
+ mt={2}
onChange={(e) => (this.description = e.target.value)}
placeholder="Enter description (optional)"
defaultValue={this.description}
/>
- <Box
- mt={2}
- sx={{
- maxHeight: this.MAX_AVAILABLE_HEIGHT,
- overflowY: "auto",
- }}
- >
- {this.state.topics.map((value, index) => {
- if (value.title === "General") {
- return null;
- }
-
- return (
- <Flex
- key={value.id || value.title}
- flexDirection="row"
- sx={{ marginBottom: 1 }}
- >
- <Input
- data-test-id={
- "dialog-topic-name-" + (props.edit ? index - 1 : index)
- }
- ref={(ref) => {
- this._inputRefs[index] = ref;
- if (ref) ref.value = value.title; // set default value
- }}
- placeholder="Topic name"
- onFocus={(e) => {
- this.lastLength = e.nativeEvent.target.value.length;
- if (this.state.focusedInputIndex === index) return;
- this.setState({ focusedInputIndex: index });
- }}
- onChange={(e) => {
- this.topics[index].title = e.target.value;
- }}
- onKeyUp={(e) => {
- if (e.nativeEvent.key === "Enter") {
- this.addTopic(index);
- } else if (
- e.nativeEvent.key === "Backspace" &&
- this.lastLength === 0 &&
- index > 0
- ) {
- this.removeTopic(index);
- }
- this.lastLength = e.nativeEvent.target.value.length;
- }}
- />
- <RebassButton
- variant="tertiary"
- sx={{ marginLeft: 1 }}
- px={2}
- py={1}
- onClick={() => this.performActionOnTopic(index)}
- >
- <Box height={20}>
- {this.state.focusedInputIndex === index ? (
- <Icon.Plus size={22} data-test-id="dialog-add-topic" />
- ) : (
- <Icon.Minus size={22} />
- )}
- </Box>
- </RebassButton>
- </Flex>
- );
- })}
- </Box>
- </Box>
+ <Flex flexDirection="row" mt={2}>
+ <Input
+ data-test-id={"dialog-nb-topic"}
+ ref={(ref) => (this._topicInputRef = ref)}
+ placeholder="Add a topic"
+ onChange={(e) => {
+ if (!this.state.isEditting) return;
+ const topics = this.state.topics.slice();
+ topics[this.state.editIndex].title = e.target.value;
+ this.setState({
+ topics,
+ });
+ }}
+ onKeyUp={(e) => {
+ if (e.nativeEvent.key === "Enter") {
+ if (this.state.isEditting) {
+ this.doneEditingTopic();
+ } else {
+ this.addTopic(e.target.value);
+ }
+ }
+ }}
+ />
+ <RebassButton
+ variant="tertiary"
+ sx={{ marginLeft: 1 }}
+ px={2}
+ py={1}
+ onClick={() => {
+ if (this.state.isEditting) {
+ this.doneEditingTopic();
+ } else {
+ this.addTopic(this._topicInputRef.value);
+ }
+ }}
+ data-test-id="dialog-nb-topic-action"
+ >
+ <Box height={20}>
+ {this.state.isEditting ? (
+ <Icon.Checkmark size={22} />
+ ) : (
+ <Icon.Plus size={22} />
+ )}
+ </Box>
+ </RebassButton>
+ </Flex>
+ {this.state.topics.map((topic, index) => (
+ <TopicItem
+ key={topic.id || topic.title || index}
+ hideActions={topic.title === "General"}
+ title={topic.title}
+ isEditing={this.state.editIndex === index}
+ onEdit={() => this.editTopic(index)}
+ onDoneEditing={() => this.doneEditingTopic()}
+ onDelete={() => this.removeTopic(index)}
+ index={index}
+ />
+ ))}
+ </Flex>
</Dialog>
);
}
@@ -201,16 +200,24 @@ export function showEditNoteDialog(notebook) {
isOpen={true}
notebook={notebook}
edit={true}
- onDone={async (nb) => {
+ onDone={async (nb, deletedTopics) => {
+ // we remove the topics from notebook
+ // beforehand so we can add them manually, later
const topics = qclone(nb.topics);
- console.log(nb, topics);
delete nb.topics;
+
+ // add the edited notebook to db
await store.add({ ...notebook, ...nb });
- await db.notebooks.notebook(notebook.id).topics.add(...topics);
+
+ // 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);
}}
- close={() => {
+ onClose={() => {
perform(false);
}}
/>
@@ -218,3 +225,63 @@ export function showEditNoteDialog(notebook) {
}
export default AddNotebookDialog;
+
+function TopicItem(props) {
+ const {
+ title,
+ onEdit,
+ onDoneEditing,
+ onDelete,
+ isEditing,
+ hideActions,
+ index,
+ } = props;
+ return (
+ <Flex
+ p={2}
+ pl={0}
+ justifyContent="space-between"
+ alignItems="center"
+ sx={{
+ borderWidth: 1,
+ borderBottomColor: isEditing ? "primary" : "border",
+ borderBottomStyle: "solid",
+ cursor: "pointer",
+ ":hover": { borderBottomColor: "primary" },
+ }}
+ onClick={isEditing ? onDoneEditing : onEdit}
+ >
+ <Flex alignItems="center" justifyContent="center">
+ <Icon.Topic />
+ <Text as="span" ml={1} fontSize="body">
+ {title}
+ </Text>
+ </Flex>
+ {!hideActions && (
+ <Flex justifyContent="center" alignItems="center">
+ <Text
+ variant="subBody"
+ color="primary"
+ sx={{ ":hover": { opacity: 0.8 } }}
+ onClick={isEditing ? onDoneEditing : onEdit}
+ data-test-id={`dialog-nb-topic-${index}-actions-edit`}
+ >
+ {isEditing ? "Done" : "Edit"}
+ </Text>
+ <Text
+ variant="subBody"
+ color="error"
+ ml={1}
+ onClick={(e) => {
+ e.stopPropagation();
+ onDelete();
+ }}
+ sx={{ ":hover": { opacity: 0.8 } }}
+ >
+ Delete
+ </Text>
+ </Flex>
+ )}
+ </Flex>
+ );
+}
diff --git a/apps/web/src/components/dialogs/buydialog.js b/apps/web/src/components/dialogs/buydialog.js
new file mode 100644
index 000000000..eb6883fb3
--- /dev/null
+++ b/apps/web/src/components/dialogs/buydialog.js
@@ -0,0 +1,113 @@
+import React from "react";
+import { Text, Flex, Button } from "rebass";
+import Dialog, { showDialog } from "./dialog";
+import * as Icon from "../icons";
+import { useStore as useUserStore } from "../../stores/user-store";
+import { upgrade } from "../../common/upgrade";
+import { showSignUpDialog } from "./signupdialog";
+
+const premiumDetails = [
+ {
+ title: "Cross Platfrom Sync",
+ description:
+ "Securely sync your notes on any device, Android, iOS, Windows, MacOS, Linux and Web!",
+ },
+ {
+ title: "Zero Knowledge",
+ description:
+ "No sneaking, no stealing. We give all the keys for your data to you. Privacy is not just a word to us. We use industry-grade XChaChaPoly1305 and Argon2 which is miles ahead other solutions making sure your data is secure and private even a million years from now.",
+ },
+ {
+ title: "Organize Notes Like Never Before",
+ description:
+ "Organize your notes using notebooks, tags and colors. Add notes to favorites for quick access. Pin most important notes and notebooks on top for quick access. You can also pin notes and notebooks to quickly access them!",
+ },
+ {
+ title: "Full Rich Text Editor with Markdown",
+ description:
+ "Unleash the power of a complete Rich Text Editor in your notes app. You can add images, links and even embed videos! We have even added full markdown support too!",
+ },
+ {
+ title: "Export Notes",
+ description:
+ "You can export your notes as PDF, Markdown, Plain text or HTML file.",
+ },
+ {
+ title: "Backup and Restore",
+ description:
+ "Backup and restore your notes anytime into your phone storage. You can encrypt all your backups if required!",
+ },
+];
+
+function BuyDialog(props) {
+ const isLoggedIn = useUserStore((store) => store.isLoggedIn);
+ const user = useUserStore((store) => store.user);
+
+ return (
+ <Dialog
+ isOpen={true}
+ title="Notesnook Pro"
+ onClose={props.onCancel}
+ showClose
+ >
+ <Flex flexDirection="column" flex={1} sx={{ overflow: "hidden" }}>
+ <Flex flexDirection="column" sx={{ overflowY: "scroll" }}>
+ {premiumDetails.map((detail) => (
+ <Flex mb={1}>
+ <Icon.CheckCircle
+ size={20}
+ color="primary"
+ sx={{ flexShrink: 0, mr: 2 }}
+ />
+ <Text variant="body">
+ {detail.title}
+ <Text variant="subBody">{detail.description}</Text>
+ </Text>
+ </Flex>
+ ))}
+ </Flex>
+ <Flex
+ flex={1}
+ flexDirection="column"
+ pt={2}
+ sx={{
+ borderRadius: "default",
+ }}
+ >
+ <Text variant="title" color="primary">
+ {isLoggedIn ? "Upgrade now" : "Try it Now"}
+ <Text variant="subBody" color="text">
+ {isLoggedIn
+ ? "Cancel anytime. No questions asked."
+ : "Start your 14 Day Trial (no credit card required)"}
+ </Text>
+ </Text>
+ <Text as="span" variant="body" fontSize="heading" color="text" mt={3}>
+ $6.99
+ <Text as="span" variant="body" color="primary" fontSize="subBody">
+ /mo
+ </Text>
+ </Text>
+ <Button
+ mt={1}
+ fontSize="body"
+ onClick={async () => {
+ props.onCancel();
+ if (isLoggedIn) {
+ await upgrade(user);
+ } else {
+ await showSignUpDialog();
+ }
+ }}
+ >
+ {isLoggedIn ? "Subscribe to Notesnook Pro" : "Sign up now"}
+ </Button>
+ </Flex>
+ </Flex>
+ </Dialog>
+ );
+}
+
+export function showBuyDialog() {
+ return showDialog((perform) => <BuyDialog onCancel={() => perform(false)} />);
+}
diff --git a/apps/web/src/components/dialogs/confirm.js b/apps/web/src/components/dialogs/confirm.js
index 3a66e02a3..c22492217 100644
--- a/apps/web/src/components/dialogs/confirm.js
+++ b/apps/web/src/components/dialogs/confirm.js
@@ -10,6 +10,7 @@ function Confirm(props) {
title={props.title}
icon={props.icon}
description={props.subtitle}
+ onClose={props.onNo}
positiveButton={{
text: props.yesText,
onClick: props.onYes,
diff --git a/apps/web/src/components/dialogs/dialog.js b/apps/web/src/components/dialogs/dialog.js
index cce412f8a..017d44390 100644
--- a/apps/web/src/components/dialogs/dialog.js
+++ b/apps/web/src/components/dialogs/dialog.js
@@ -4,34 +4,42 @@ import { Flex, Text, Button as RebassButton } from "rebass";
import ThemeProvider from "../theme-provider";
import * as Icon from "../icons";
import Modal from "react-modal";
-import useMobile from "../../utils/use-mobile";
import { useTheme } from "emotion-theming";
function Dialog(props) {
- const isMobile = useMobile();
const theme = useTheme();
-
return (
<Modal
isOpen={props.isOpen || false}
- shouldCloseOnOverlayClick={true}
- onRequestClose={props?.negativeButton?.onClick}
+ onRequestClose={props.onClose}
+ shouldCloseOnEsc
+ shouldCloseOnOverlayClick
+ onAfterOpen={(e) => {
+ // we need this work around because ReactModal content spreads over the overlay
+ const child = e.contentEl.firstElementChild;
+ e.contentEl.onclick = function (e) {
+ if (
+ e.x < child.offsetLeft ||
+ e.x > child.offsetLeft + child.clientWidth ||
+ e.y < child.offsetTop ||
+ e.y > child.offsetTop + child.clientHeight
+ ) {
+ props.onClose();
+ }
+ };
+ }}
style={{
content: {
- top: isMobile ? 0 : "50%",
- left: isMobile ? 0 : "50%",
- right: "auto",
- bottom: "auto",
- marginRight: isMobile ? 0 : "-50%",
- transform: isMobile ? 0 : "translate(-50%, -50%)",
- borderWidth: 0,
- borderRadius: theme.radii["default"],
- backgroundColor: theme.colors.background,
- color: theme.colors.text,
- boxShadow: "4px 5px 18px 2px #00000038",
- width: isMobile ? "100%" : "30%",
+ top: 0,
+ left: 0,
+ right: 0,
+ bottom: 0,
+ display: "flex",
+ justifyContent: "center",
+ backgroundColor: undefined,
padding: 0,
overflowY: "hidden",
+ zIndex: 0,
},
overlay: {
zIndex: 999,
@@ -39,61 +47,97 @@ function Dialog(props) {
},
}}
>
- <Flex p={30} flexDirection="column">
+ <Flex
+ p={30}
+ flexDirection="column"
+ width={["100%", "90%", "33%"]}
+ maxHeight={["100%", "80%", "70%"]}
+ height={["100%", "auto", "auto"]}
+ bg="background"
+ alignSelf={"center"}
+ m={[0, 2, 2]}
+ sx={{
+ position: "relative",
+ overflow: "hidden",
+ boxShadow: "4px 5px 18px 2px #00000038",
+ borderRadius: "default",
+ }}
+ >
+ {props.showClose && (
+ <Icon.Close
+ sx={{ position: "absolute", top: 0, right: 30, mt: 38 }}
+ size={26}
+ onClick={props.onClose}
+ />
+ )}
<Flex
variant="columnCenter"
pb={2}
mb={3}
sx={{ borderBottom: "1px solid", borderColor: "border" }}
>
- <props.icon size={props.iconSize || 38} color="primary" />
- <Text variant="heading" textAlign="center" color="text" mx={1} mt={1}>
+ {props.icon && (
+ <props.icon size={props.iconSize || 38} color="primary" />
+ )}
+ <Text
+ variant="heading"
+ textAlign="center"
+ color="text"
+ mx={1}
+ mt={props.icon && 1}
+ >
{props.title}
</Text>
- <Text variant="body" textAlign="center" color="gray" mx={1} mt={1}>
- {props.description}
- </Text>
- </Flex>
- {props.children}
- <Flex
- sx={{ justifyContent: props.buttonsAlignment || "flex-end" }}
- mt={3}
- >
- {props.positiveButton && (
- <RebassButton
- variant="primary"
- data-test-id="dialog-yes"
- sx={{ opacity: props.positiveButton.disabled ? 0.7 : 1 }}
- mx={1}
- disabled={props.positiveButton.disabled || false}
- onClick={
- !props.positiveButton.disabled
- ? props.positiveButton.onClick
- : undefined
- }
- >
- {props.positiveButton.loading ? (
- <Icon.Loading rotate={true} color="static" />
- ) : (
- props.positiveButton.text || "OK"
- )}
- </RebassButton>
- )}
- {props.negativeButton && (
- <RebassButton
- variant="secondary"
- data-test-id="dialog-no"
- onClick={props.negativeButton.onClick}
- >
- {props.negativeButton.text || "Cancel"}
- </RebassButton>
+ {props.description && (
+ <Text variant="body" textAlign="center" color="gray" mx={1} mt={1}>
+ {props.description}
+ </Text>
)}
</Flex>
+ {props.children}
+
+ {(props.positiveButton || props.negativeButton) && (
+ <Flex
+ sx={{ justifyContent: props.buttonsAlignment || "flex-end" }}
+ mt={3}
+ >
+ {props.positiveButton && (
+ <RebassButton
+ variant="primary"
+ data-test-id="dialog-yes"
+ sx={{ opacity: props.positiveButton.disabled ? 0.7 : 1 }}
+ mx={1}
+ disabled={props.positiveButton.disabled || false}
+ onClick={
+ !props.positiveButton.disabled
+ ? props.positiveButton.onClick
+ : undefined
+ }
+ >
+ {props.positiveButton.loading ? (
+ <Icon.Loading rotate={true} color="static" />
+ ) : (
+ props.positiveButton.text || "OK"
+ )}
+ </RebassButton>
+ )}
+ {props.negativeButton && (
+ <RebassButton
+ variant="secondary"
+ data-test-id="dialog-no"
+ onClick={props.negativeButton.onClick}
+ >
+ {props.negativeButton.text || "Cancel"}
+ </RebassButton>
+ )}
+ </Flex>
+ )}
{props.footer}
</Flex>
</Modal>
);
}
+
export default Dialog;
export function showDialog(dialog) {
diff --git a/apps/web/src/components/dialogs/exportdialog.js b/apps/web/src/components/dialogs/exportdialog.js
index 912a2cc5c..59a81a468 100644
--- a/apps/web/src/components/dialogs/exportdialog.js
+++ b/apps/web/src/components/dialogs/exportdialog.js
@@ -14,6 +14,7 @@ function ExportDialog(props) {
icon={props.icon}
description="You can export your note to Markdown, HTML, or Text."
buttonsAlignment="center"
+ onClose={props.onClose}
negativeButton={{
onClick: props.onClose,
text: "Cancel",
diff --git a/apps/web/src/components/dialogs/logindialog.js b/apps/web/src/components/dialogs/logindialog.js
index 8e63ec498..081e9402b 100644
--- a/apps/web/src/components/dialogs/logindialog.js
+++ b/apps/web/src/components/dialogs/logindialog.js
@@ -21,7 +21,7 @@ function LoginDialog(props) {
title={"Sign in to Your Account"}
description={"Signing in allows you to sync your notes across devices."}
icon={Icon.Login}
- onCloseClick={onClose}
+ onClose={onClose}
negativeButton={{ text: "Cancel", onClick: onClose }}
positiveButton={{
text: "Sign me in",
diff --git a/apps/web/src/components/dialogs/move-note-dialog.js b/apps/web/src/components/dialogs/move-note-dialog.js
index 5b2c94e29..3153f3c47 100644
--- a/apps/web/src/components/dialogs/move-note-dialog.js
+++ b/apps/web/src/components/dialogs/move-note-dialog.js
@@ -14,7 +14,13 @@ class MoveDialog extends React.Component {
selectedTopic;
state = {
currentOpenedIndex: -1,
- notebooks: db.notebooks.all,
+ notebooks: [
+ ...db.notebooks.all,
+ ...db.notebooks.all,
+ ...db.notebooks.all,
+ ...db.notebooks.all,
+ ...db.notebooks.all,
+ ],
};
async addNotebook(input) {
@@ -37,12 +43,13 @@ class MoveDialog extends React.Component {
description={"Organize your notes by adding them to notebooks."}
icon={Icon.Move}
buttonsAlignment="center"
+ onClose={props.onClose}
negativeButton={{
text: "Cancel",
onClick: props.onClose,
}}
>
- <Box>
+ <Flex flexDirection="column" sx={{ overflowY: "hidden" }}>
<Text variant="title">Notebooks</Text>
<Flex flexDirection="row" my={2}>
<Input
@@ -71,7 +78,6 @@ class MoveDialog extends React.Component {
borderWidth: 1,
borderStyle: "solid",
borderColor: "border",
- maxHeight: 5 * 46,
overflowY: "auto",
}}
>
@@ -129,7 +135,7 @@ class MoveDialog extends React.Component {
</Flex>
))}
</Box>
- </Box>
+ </Flex>
</Dialog>
);
}
diff --git a/apps/web/src/components/dialogs/password-dialog.js b/apps/web/src/components/dialogs/password-dialog.js
index e5d3ab432..1b5373519 100644
--- a/apps/web/src/components/dialogs/password-dialog.js
+++ b/apps/web/src/components/dialogs/password-dialog.js
@@ -22,6 +22,7 @@ function PasswordDialog(props) {
title={props.title}
description={props.subtitle}
icon={props.icon}
+ onClose={props.onCancel}
positiveButton={{
text: props.positiveButtonText,
onClick: submit,
diff --git a/apps/web/src/components/dialogs/signupdialog.js b/apps/web/src/components/dialogs/signupdialog.js
index b6466663a..a4fdc45cb 100644
--- a/apps/web/src/components/dialogs/signupdialog.js
+++ b/apps/web/src/components/dialogs/signupdialog.js
@@ -23,7 +23,7 @@ function SignUpDialog(props) {
title={"Create a new Account"}
description={"Sign up for a 14-day free trial (no credit card)."}
icon={Icon.Signup}
- onCloseClick={onClose}
+ onClose={onClose}
negativeButton={{ text: "Cancel", onClick: onClose }}
buttonsAlignment="center"
positiveButton={{
diff --git a/apps/web/src/components/dialogs/topicdialog.js b/apps/web/src/components/dialogs/topicdialog.js
index 674268eeb..c88cd5ec3 100644
--- a/apps/web/src/components/dialogs/topicdialog.js
+++ b/apps/web/src/components/dialogs/topicdialog.js
@@ -13,19 +13,20 @@ function TopicDialog(props) {
<Dialog
isOpen={true}
title={props.title}
- description="You can create as many topics as you want."
+ description={props.subtitle}
icon={props.icon}
positiveButton={{
text: "Create topic",
onClick: () => {
- props.onYes(ref.current.value);
+ props.onAction(ref.current.value);
},
}}
- negativeButton={{ text: "Cancel", onClick: props.onNo }}
+ onClose={props.onClose}
+ negativeButton={{ text: "Cancel", onClick: props.onClose }}
>
<Box my={1}>
<Input
- data-test-id="edit-topic-dialog"
+ data-test-id="dialog-edit-topic"
autoFocus
ref={ref}
placeholder="Topic title"
@@ -40,6 +41,7 @@ export function showTopicDialog(notebook) {
return showDialog((perform) => (
<TopicDialog
title={"Create a Topic"}
+ subtitle={"You can create as many topics as you want."}
icon={Icon.Topic}
onNo={() => {
perform(false);
@@ -57,13 +59,12 @@ export function showTopicDialog(notebook) {
export function showEditTopicDialog(topic) {
return showDialog((perform) => (
<TopicDialog
- title={"Topic"}
+ title={"Edit Topic"}
+ subtitle={`You are editing "${topic.title}" topic.`}
icon={Icon.Topic}
topic={topic}
- onNo={() => {
- perform(false);
- }}
- onYes={async (t) => {
+ onClose={() => perform(false)}
+ onAction={async (t) => {
await db.notebooks
.notebook(topic.notebookId)
.topics.add({ ...topic, title: t });
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index ffdbde68f..758bcb180 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -20,7 +20,6 @@ import RouteContainer from "../route-container";
import useMobile from "../../utils/use-mobile";
function Editor() {
- console.log("rendering editor");
const sessionState = useStore((store) => store.session.state);
const setSession = useStore((store) => store.setSession);
const saveSession = useStore((store) => store.saveSession);
@@ -30,7 +29,7 @@ function Editor() {
const isFocusMode = useAppStore((store) => store.isFocusMode);
const isMobile = useMobile();
const isTrial = useUserStore(
- (store) => store.user.notesnook?.subscription?.isTrial
+ (store) => store.user?.notesnook?.subscription?.isTrial
);
const isLoggedin = useUserStore((store) => store.isLoggedIn);
diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.js
index a3f4d696c..f5f5ad16e 100644
--- a/apps/web/src/components/icons/index.js
+++ b/apps/web/src/components/icons/index.js
@@ -83,6 +83,7 @@ export const DarkMode = createIcon(Icons.mdiWeatherNight);
export const LightMode = createIcon(Icons.mdiWeatherSunny);
export const Theme = createIcon(Icons.mdiThemeLightDark);
export const Checkmark = createIcon(Icons.mdiCheck);
+export const CheckCircle = createIcon(Icons.mdiCheckCircle);
export const Properties = createIcon(Icons.mdiDotsHorizontal);
@@ -102,3 +103,6 @@ export const ToggleUnchecked = createIcon(Icons.mdiToggleSwitchOff);
export const ToggleChecked = createIcon(Icons.mdiToggleSwitch);
export const Backup = createIcon(Icons.mdiBackupRestore);
+export const Buy = createIcon(Icons.mdiCurrencyUsdCircleOutline);
+
+export const Edit = createIcon(Icons.mdiPencil);
diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.js
index 6cbc53a41..f5fe6abfc 100644
--- a/apps/web/src/components/notebook/index.js
+++ b/apps/web/src/components/notebook/index.js
@@ -17,7 +17,9 @@ function menuItems(notebook, index) {
},
{
title: "Edit",
- onClick: () => showEditNoteDialog(notebook),
+ onClick: async () => {
+ if (await showEditNoteDialog(notebook)) store.refresh();
+ },
},
{
title: "Delete",
diff --git a/apps/web/src/stores/user-store.js b/apps/web/src/stores/user-store.js
index 517312168..8352f912e 100644
--- a/apps/web/src/stores/user-store.js
+++ b/apps/web/src/stores/user-store.js
@@ -9,7 +9,7 @@ class UserStore extends BaseStore {
isLoggingIn = false;
isSigningIn = false;
isSyncing = false;
- user = {};
+ user = undefined;
init = () => {
return db.user.get().then(async (user) => {
diff --git a/apps/web/src/views/notebooks.js b/apps/web/src/views/notebooks.js
index 771a8d6d0..0c33ff654 100644
--- a/apps/web/src/views/notebooks.js
+++ b/apps/web/src/views/notebooks.js
@@ -76,7 +76,7 @@ function Notebooks() {
await add(nb);
setOpen(false);
}}
- close={() => {
+ onClose={() => {
setOpen(false);
}}
/>
diff --git a/apps/web/src/views/topics.js b/apps/web/src/views/topics.js
index 17377f3b1..c2d271acb 100644
--- a/apps/web/src/views/topics.js
+++ b/apps/web/src/views/topics.js
@@ -31,7 +31,7 @@ function Topics(props) {
context={{ notebookId }}
placeholder={Flex}
button={{
- content: "Create a new topic",
+ content: "Add a new topic",
onClick: async () => {
await showTopicDialog(notebookId);
},