Skip to content

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

refactor: cleanup base dialog component

thecodrr632819d3af47
diff --git a/apps/web/src/components/dialogs/add-notebook-dialog.js b/apps/web/src/components/dialogs/add-notebook-dialog.js
index 216af18ee..6557a0e7f 100644
--- a/apps/web/src/components/dialogs/add-notebook-dialog.js
+++ b/apps/web/src/components/dialogs/add-notebook-dialog.js
@@ -83,86 +83,6 @@ class AddNotebookDialog extends React.Component {
isOpen={props.isOpen}
title="Notebook"
icon={Icon.Notebook}
- content={
- <Box my={1}>
- <Input
- autoFocus
- variant="default"
- onChange={e => (this.title = e.target.value)}
- placeholder="Enter name"
- defaultValue={this.title}
- />
- <Input
- variant="default"
- sx={{ marginTop: 1 }}
- onChange={e => (this.description = e.target.value)}
- placeholder="Enter description (optional)"
- defaultValue={this.description}
- />
- <Text variant="body" fontWeight="bold" my={1}>
- Topics (optional):
- </Text>
- <Box
- sx={{
- maxHeight: this.MAX_AVAILABLE_HEIGHT,
- overflowY: "auto",
- marginBottom: 1
- }}
- >
- {this.state.topics.map((value, index) => (
- <Flex
- key={index.toString()}
- flexDirection="row"
- sx={{ marginBottom: 1 }}
- >
- <Input
- ref={ref => {
- this._inputRefs[index] = ref;
- if (ref) ref.value = value; // set default value
- }}
- variant="default"
- 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] = 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} />
- ) : (
- <Icon.Minus size={22} />
- )}
- </Box>
- </RebassButton>
- </Flex>
- ))}
- </Box>
- </Box>
- }
positiveButton={{
text: props.edit ? "Edit" : "Add",
onClick: () => {
@@ -175,7 +95,86 @@ class AddNotebookDialog extends React.Component {
}
}}
negativeButton={{ text: "Cancel", onClick: props.close }}
- />
+ >
+ <Box my={1}>
+ <Input
+ autoFocus
+ variant="default"
+ onChange={e => (this.title = e.target.value)}
+ placeholder="Enter name"
+ defaultValue={this.title}
+ />
+ <Input
+ variant="default"
+ sx={{ marginTop: 1 }}
+ onChange={e => (this.description = e.target.value)}
+ placeholder="Enter description (optional)"
+ defaultValue={this.description}
+ />
+ <Text variant="body" fontWeight="bold" my={1}>
+ Topics (optional):
+ </Text>
+ <Box
+ sx={{
+ maxHeight: this.MAX_AVAILABLE_HEIGHT,
+ overflowY: "auto",
+ marginBottom: 1
+ }}
+ >
+ {this.state.topics.map((value, index) => (
+ <Flex
+ key={index.toString()}
+ flexDirection="row"
+ sx={{ marginBottom: 1 }}
+ >
+ <Input
+ ref={ref => {
+ this._inputRefs[index] = ref;
+ if (ref) ref.value = value; // set default value
+ }}
+ variant="default"
+ 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] = 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} />
+ ) : (
+ <Icon.Minus size={22} />
+ )}
+ </Box>
+ </RebassButton>
+ </Flex>
+ ))}
+ </Box>
+ </Box>
+ </Dialog>
);
}
}
diff --git a/apps/web/src/components/dialogs/confirm.js b/apps/web/src/components/dialogs/confirm.js
index 8f77ae039..2b0ff12a9 100644
--- a/apps/web/src/components/dialogs/confirm.js
+++ b/apps/web/src/components/dialogs/confirm.js
@@ -8,17 +8,16 @@ function Confirm(props) {
isOpen={true}
title={props.title}
icon={props.icon}
- content={
- <Box my={1}>
- <Text textAlign="center">{props.message}</Text>
- </Box>
- }
positiveButton={{
text: "Yes",
onClick: props.onYes
}}
negativeButton={{ text: "No", onClick: props.onNo }}
- />
+ >
+ <Box my={1}>
+ <Text textAlign="center">{props.message}</Text>
+ </Box>
+ </Dialog>
);
}
diff --git a/apps/web/src/components/dialogs/dialog.js b/apps/web/src/components/dialogs/dialog.js
index f71068163..ea7dc725a 100644
--- a/apps/web/src/components/dialogs/dialog.js
+++ b/apps/web/src/components/dialogs/dialog.js
@@ -38,32 +38,14 @@ function Dialog(props) {
}}
>
<Flex flexDirection="column">
- <Flex
- flexDirection="row"
- alignItems="center"
- alignSelf="center"
- justifyContent="center"
- color="primary"
- sx={{ paddingBottom: 2 }}
- >
+ <Flex alignItems="center" justifyContent="center" pb={2}>
<props.icon size={props.iconSize || 38} color="primary" />
- <Text
- mx={1}
- as="span"
- variant="title"
- fontSize={"heading"}
- textAlign="center"
- >
+ <Text variant="heading" color="primary" mx={1}>
{props.title}
</Text>
</Flex>
- {props.content}
- <Flex
- flexDirection="row"
- sx={{ marginTop: 3 }}
- justifyContent="center"
- alignItems="center"
- >
+ {props.children}
+ <Flex mt={3} justifyContent="center" alignItems="center">
{props.positiveButton && (
<RebassButton
variant="primary"
diff --git a/apps/web/src/components/dialogs/logindialog.js b/apps/web/src/components/dialogs/logindialog.js
index 61d054b45..a276c032a 100644
--- a/apps/web/src/components/dialogs/logindialog.js
+++ b/apps/web/src/components/dialogs/logindialog.js
@@ -34,17 +34,16 @@ function LoginDialog(props) {
.catch(e => setError(e.message));
}
}}
- content={
- <Form mt={1} gutter={2} form={form}>
- <Input autoFocus name="username" title="Username" />
- <PasswordInput />
- <Button variant="anchor" onClick={showSignUpDialog()}>
- Create a New Account
- </Button>
- {error && <Text variant="error">{error}</Text>}
- </Form>
- }
- />
+ >
+ <Form mt={1} gutter={2} form={form}>
+ <Input autoFocus name="username" title="Username" />
+ <PasswordInput />
+ <Button variant="anchor" onClick={showSignUpDialog}>
+ Create a New Account
+ </Button>
+ {error && <Text variant="error">{error}</Text>}
+ </Form>
+ </Dialog>
);
}
diff --git a/apps/web/src/components/dialogs/move-note-dialog.js b/apps/web/src/components/dialogs/move-note-dialog.js
index 9bd48ab62..8aac21752 100644
--- a/apps/web/src/components/dialogs/move-note-dialog.js
+++ b/apps/web/src/components/dialogs/move-note-dialog.js
@@ -36,144 +36,6 @@ class MoveDialog extends React.Component {
? Icon.Topic
: Icon.Notebook
}
- content={
- <Box>
- <Flex alignContent="center" justifyContent="space-between" my={1}>
- <Flex>
- <Text
- onClick={() => {
- let item = this.history.pop();
- this.setState({ ...item });
- }}
- sx={{
- display: this.history.length ? "block" : "none",
- ":hover": { color: "primary" },
- marginRight: 2
- }}
- >
- <Icon.ArrowLeft />
- </Text>
- <Text variant="title">{title}</Text>
- </Flex>
- <Text
- onClick={() => {
- if (mode === "write") {
- this.setState({ mode: "read" });
- return;
- }
- this.setState({ mode: "write" });
- setTimeout(() => {
- this._inputRef.focus();
- }, 0);
- }}
- sx={{
- display: type === "notes" ? "none" : "block",
- ":hover": { color: "primary" }
- }}
- >
- {mode === "read" ? <Icon.Plus /> : <Icon.Minus />}
- </Text>
- </Flex>
- <Input
- ref={ref => (this._inputRef = ref)}
- variant="default"
- sx={{ display: mode === "write" ? "block" : "none" }}
- my={1}
- placeholder={
- type === "notebooks" ? "Notebook name" : "Topic name"
- }
- onKeyUp={async e => {
- if (
- e.nativeEvent.key === "Enter" &&
- e.target.value.length > 0
- ) {
- if (type === "notebooks") {
- await db.notebooks.add({
- title: e.target.value
- });
- this.setState({ items: db.notebooks.all });
- } else {
- await db.notebooks
- .notebook(this.selectedNotebook.id)
- .topics.add(e.target.value);
- this.setState({
- items: db.notebooks.notebook(this.selectedNotebook.id)
- .topics.all
- });
- }
- this._inputRef.value = "";
- this.setState({ mode: "read" });
- }
- }}
- />
- <Box
- sx={{
- borderWidth: 1,
- borderStyle: "solid",
- borderColor: "border",
- maxHeight: 8 * 30,
- overflowY: "auto"
- }}
- >
- {items.length ? (
- items.map(item => {
- return (
- <Flex
- key={item.title + item.dateCreated}
- sx={{
- borderWidth: 1,
- padding: 2,
- borderBottomColor: "border",
- borderBottomStyle: "solid",
- cursor: "pointer",
- ":hover": { borderBottomColor: "primary" }
- }}
- onClick={() => {
- this.history.push({
- title,
- items,
- type
- });
- if (type === "notebooks") {
- this.setState({
- type: "topics",
- items: item.topics,
- title: item.title
- });
- this.selectedNotebook = item;
- } else if (type === "topics") {
- this.setState({
- type: "notes",
- title: `${this.selectedNotebook.title} - ${item.title}`,
- items: db.notebooks
- .notebook(this.selectedNotebook.id)
- .topics.topic(item.title).all
- });
- this.selectedTopic = item.title;
- }
- }}
- >
- <Text sx={{ width: "80%" }}>{item.title}</Text>
- {item.totalNotes !== undefined && (
- <Text sx={{ width: "20%", textAlign: "right" }}>
- {item.totalNotes + " Notes"}
- </Text>
- )}
- </Flex>
- );
- })
- ) : (
- <Text
- py={2}
- px={2}
- sx={{ textAlign: "center", fontStyle: "italic" }}
- >
- Nothing here
- </Text>
- )}
- </Box>
- </Box>
- }
positiveButton={{
text: "Move",
onClick: async () => {
@@ -192,7 +54,139 @@ class MoveDialog extends React.Component {
disabled: type !== "notes"
}}
negativeButton={{ text: "Cancel", onClick: props.onClose }}
- />
+ >
+ <Box>
+ <Flex alignContent="center" justifyContent="space-between" my={1}>
+ <Flex>
+ <Text
+ onClick={() => {
+ let item = this.history.pop();
+ this.setState({ ...item });
+ }}
+ sx={{
+ display: this.history.length ? "block" : "none",
+ ":hover": { color: "primary" },
+ marginRight: 2
+ }}
+ >
+ <Icon.ArrowLeft />
+ </Text>
+ <Text variant="title">{title}</Text>
+ </Flex>
+ <Text
+ onClick={() => {
+ if (mode === "write") {
+ this.setState({ mode: "read" });
+ return;
+ }
+ this.setState({ mode: "write" });
+ setTimeout(() => {
+ this._inputRef.focus();
+ }, 0);
+ }}
+ sx={{
+ display: type === "notes" ? "none" : "block",
+ ":hover": { color: "primary" }
+ }}
+ >
+ {mode === "read" ? <Icon.Plus /> : <Icon.Minus />}
+ </Text>
+ </Flex>
+ <Input
+ ref={ref => (this._inputRef = ref)}
+ variant="default"
+ sx={{ display: mode === "write" ? "block" : "none" }}
+ my={1}
+ placeholder={type === "notebooks" ? "Notebook name" : "Topic name"}
+ onKeyUp={async e => {
+ if (e.nativeEvent.key === "Enter" && e.target.value.length > 0) {
+ if (type === "notebooks") {
+ await db.notebooks.add({
+ title: e.target.value
+ });
+ this.setState({ items: db.notebooks.all });
+ } else {
+ await db.notebooks
+ .notebook(this.selectedNotebook.id)
+ .topics.add(e.target.value);
+ this.setState({
+ items: db.notebooks.notebook(this.selectedNotebook.id)
+ .topics.all
+ });
+ }
+ this._inputRef.value = "";
+ this.setState({ mode: "read" });
+ }
+ }}
+ />
+ <Box
+ sx={{
+ borderWidth: 1,
+ borderStyle: "solid",
+ borderColor: "border",
+ maxHeight: 8 * 30,
+ overflowY: "auto"
+ }}
+ >
+ {items.length ? (
+ items.map(item => {
+ return (
+ <Flex
+ key={item.title + item.dateCreated}
+ sx={{
+ borderWidth: 1,
+ padding: 2,
+ borderBottomColor: "border",
+ borderBottomStyle: "solid",
+ cursor: "pointer",
+ ":hover": { borderBottomColor: "primary" }
+ }}
+ onClick={() => {
+ this.history.push({
+ title,
+ items,
+ type
+ });
+ if (type === "notebooks") {
+ this.setState({
+ type: "topics",
+ items: item.topics,
+ title: item.title
+ });
+ this.selectedNotebook = item;
+ } else if (type === "topics") {
+ this.setState({
+ type: "notes",
+ title: `${this.selectedNotebook.title} - ${item.title}`,
+ items: db.notebooks
+ .notebook(this.selectedNotebook.id)
+ .topics.topic(item.title).all
+ });
+ this.selectedTopic = item.title;
+ }
+ }}
+ >
+ <Text sx={{ width: "80%" }}>{item.title}</Text>
+ {item.totalNotes !== undefined && (
+ <Text sx={{ width: "20%", textAlign: "right" }}>
+ {item.totalNotes + " Notes"}
+ </Text>
+ )}
+ </Flex>
+ );
+ })
+ ) : (
+ <Text
+ py={2}
+ px={2}
+ sx={{ textAlign: "center", fontStyle: "italic" }}
+ >
+ Nothing here
+ </Text>
+ )}
+ </Box>
+ </Box>
+ </Dialog>
);
}
}
diff --git a/apps/web/src/components/dialogs/password-dialog.js b/apps/web/src/components/dialogs/password-dialog.js
index 246e15750..5c959d6f0 100644
--- a/apps/web/src/components/dialogs/password-dialog.js
+++ b/apps/web/src/components/dialogs/password-dialog.js
@@ -21,38 +21,37 @@ function PasswordDialog(props) {
isOpen={true}
title={props.title}
icon={props.icon}
- content={
- <Box my={1}>
- <Input
- ref={passwordRef}
- autoFocus
- variant={isWrong ? "error" : "default"}
- type="password"
- placeholder="Enter vault password"
- onKeyUp={async e => {
- if (e.key === "Enter") {
- await submit();
- } else {
- setIsWrong(false);
- }
- }}
- />
- {isWrong && (
- <Flex alignItems="center" color="error" mt={2}>
- <Icon.Alert size={16} color="error" />
- <Text ml={1} fontSize={"subBody"}>
- Wrong password
- </Text>
- </Flex>
- )}
- </Box>
- }
positiveButton={{
text: props.positiveButtonText,
onClick: submit
}}
negativeButton={{ text: "Cancel", onClick: props.onCancel }}
- />
+ >
+ <Box my={1}>
+ <Input
+ ref={passwordRef}
+ autoFocus
+ variant={isWrong ? "error" : "default"}
+ type="password"
+ placeholder="Enter vault password"
+ onKeyUp={async e => {
+ if (e.key === "Enter") {
+ await submit();
+ } else {
+ setIsWrong(false);
+ }
+ }}
+ />
+ {isWrong && (
+ <Flex alignItems="center" color="error" mt={2}>
+ <Icon.Alert size={16} color="error" />
+ <Text ml={1} fontSize={"subBody"}>
+ Wrong password
+ </Text>
+ </Flex>
+ )}
+ </Box>
+ </Dialog>
);
}
diff --git a/apps/web/src/components/dialogs/signupdialog.js b/apps/web/src/components/dialogs/signupdialog.js
index 02ad64a7f..65e72348f 100644
--- a/apps/web/src/components/dialogs/signupdialog.js
+++ b/apps/web/src/components/dialogs/signupdialog.js
@@ -31,15 +31,14 @@ function SignUpDialog(props) {
.catch(error => setError(`Couldn't signup. Error: ${error}`)); */
}
}}
- content={
- <Form mt={1} gutter={2} form={form}>
- <Input autoFocus title="Username" name="username" />
- <EmailInput />
- <PasswordInput confirm />
- {error && <Text variant="error">{error}</Text>}
- </Form>
- }
- />
+ >
+ <Form mt={1} gutter={2} form={form}>
+ <Input autoFocus title="Username" name="username" />
+ <EmailInput />
+ <PasswordInput confirm />
+ {error && <Text variant="error">{error}</Text>}
+ </Form>
+ </Dialog>
);
}
diff --git a/apps/web/src/components/dialogs/topicdialog.js b/apps/web/src/components/dialogs/topicdialog.js
index c65a23f08..5b5e92f71 100644
--- a/apps/web/src/components/dialogs/topicdialog.js
+++ b/apps/web/src/components/dialogs/topicdialog.js
@@ -13,23 +13,22 @@ function TopicDialog(props) {
isOpen={true}
title={props.title}
icon={props.icon}
- content={
- <Box my={1}>
- <Input
- variant="default"
- placeholder="name"
- onChange={e => {
- setTopic(e.target.value);
- }}
- ></Input>
- </Box>
- }
positiveButton={{
text: "Add",
onClick: props.onYes.bind(this, topic)
}}
negativeButton={{ text: "Cancel", onClick: props.onNo }}
- />
+ >
+ <Box my={1}>
+ <Input
+ variant="default"
+ placeholder="name"
+ onChange={e => {
+ setTopic(e.target.value);
+ }}
+ ></Input>
+ </Box>
+ </Dialog>
);
}