A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: impl api for opening confirmation dialog
thecodrr967aebcf9cb9
diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex 683ecd25e..72d96d19e 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -169,6 +169,7 @@ function App() {</Flex></Flex></Flex>+ <Box id="dialogContainer" /><Box id="snackbarContainer" /></Flex></ThemeProvider>diff --git a/apps/web/src/components/dialogs/index.js b/apps/web/src/components/dialogs/index.jsindex 7e4263a51..9e828a7da 100644--- a/apps/web/src/components/dialogs/index.js+++ b/apps/web/src/components/dialogs/index.js@@ -1,14 +1,21 @@-import React, { useState } from "react";+import React, { useState, useEffect } from "react";+import ReactDOM from "react-dom";import { Flex, Box, Text, Button as RebassButton } from "rebass";import { Input, Checkbox, Label } from "@rebass/forms";import * as Icon from "react-feather";import theme from "../../theme";import Modal from "react-modal";+import { ThemeProvider } from "emotion-theming";const Dialog = props => {+ const [open, setOpen] = useState(false);+ Dialog.close = () => setOpen(false);+ useEffect(() => {+ setOpen(props.open);+ }, [props.open]);return (<Modal- isOpen={props.open}+ isOpen={open}style={{content: {top: "50%",@@ -55,16 +62,23 @@ const Dialog = props => {</Text></Flex>{props.content}- <Flex flexDirection="row" justifyContent="center" alignItems="center">+ <Flex+ flexDirection="row"+ my={1}+ justifyContent="center"+ alignItems="center"+ ><RebassButtonvariant="primary"mx={1}+ width={"25%"}onClick={props.positiveButton.click}>{props.positiveButton.text || "OK"}</RebassButton><RebassButtonvariant="secondary"+ width={"25%"}onClick={props.negativeButton.click}>{props.negativeButton.text || "Cancel"}@@ -178,15 +192,15 @@ export const CreateNotebookDialog = props => {);};-export const ConfirmationDialog = props => {- return (+const ConfirmationDialog = props => (+ <ThemeProvider theme={theme}><Dialog- open={props.open}+ open={true}title={props.title}icon={props.icon}content={<Box my={1}>- <Text>{props.description}</Text>+ <Text>{props.message}</Text></Box>}positiveButton={{@@ -195,5 +209,27 @@ export const ConfirmationDialog = props => {}}negativeButton={{ text: "No", click: props.onNo }}/>- );+ </ThemeProvider>+);++export const ask = (icon, title, message) => {+ const root = document.querySelector("dialogContainer");+ if (root) {+ return new Promise((resolve, _) => {+ ReactDOM.render(+ <ConfirmationDialog+ title={title}+ message={message}+ icon={icon}+ onNo={() => {+ Dialog.close();+ resolve(false);+ }}+ onYes={() => resolve(true)}+ />,+ root+ );+ });+ }+ return Promise.reject("No element with id 'dialogContainer'");};diff --git a/apps/web/src/views/Notebooks.js b/apps/web/src/views/Notebooks.jsindex 728c371b4..eebff9e3b 100644--- a/apps/web/src/views/Notebooks.js+++ b/apps/web/src/views/Notebooks.js@@ -10,7 +10,7 @@ import Notebook from "../components/notebook";import Topic from "../components/topic";import Note from "../components/note";import { routes, navigationEvents, goBack as p_goBack } from "../navigation";-import { CreateNotebookDialog } from "../components/dialogs";+import { CreateNotebookDialog, ask } from "../components/dialogs";const history = [{}];const Notebooks = props => {@@ -23,9 +23,11 @@ const Notebooks = props => {setNotebooks(db.getNotebooks());}onRefresh();- navigationEvents.onWillNavigateAway = routeName => {- if (routeName !== "notebooks" && intent === "moveNote") {- return window.confirm(+ navigationEvents.onWillNavigateAway = async routeName => {+ if (intent === "moveNote") {+ return await ask(+ Icon.Move,+ "Move","Are you sure you want to navigate away? Your note selection will be lost.");}