Skip to content

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

feat: add basic notebooks logic & ui

thecodrrc534af7ffe4c
diff --git a/apps/web/package.json b/apps/web/package.json
index a3620c621..a3e3f7994 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -12,6 +12,7 @@
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-feather": "^2.0.3",
+ "react-modal": "^3.11.1",
"react-quill": "^1.3.3",
"react-scripts": "3.2.0",
"react-simple-dropdown": "^3.2.3",
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index 5c5c8efc1..411ee3605 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -35,7 +35,7 @@ const NavMenuItem = props => {
};
function App() {
- const [selectedIndex, setSelectedIndex] = useState(0);
+ const [selectedIndex, setSelectedIndex] = useState(1);
return (
<ThemeProvider theme={theme}>
<Flex height="100%" alignContent="stretch">
diff --git a/apps/web/src/components/button/index.js b/apps/web/src/components/button/index.js
new file mode 100644
index 000000000..20704900d
--- /dev/null
+++ b/apps/web/src/components/button/index.js
@@ -0,0 +1,30 @@
+import React from "react";
+import { Flex, Text } from "rebass";
+import { ButtonPressedStyle } from "../../theme";
+
+const Button = props => (
+ <Flex
+ bg="accent"
+ width="full"
+ py={3}
+ px={3}
+ flexDirection="row"
+ alignItems="center"
+ sx={{
+ borderRadius: "default",
+ marginBottom: 2,
+ color: "fontSecondary",
+ fontFamily: "body",
+ fontWeight: "body",
+ ...ButtonPressedStyle
+ }}
+ onClick={props.onClick}
+ >
+ {props.Icon && <props.Icon />}
+ <Text className="unselectable" mx={1}>
+ {props.content}
+ </Text>
+ </Flex>
+);
+
+export default Button;
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 6d5a4951f..004ac5ab9 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -1,4 +1,4 @@
-import React, { useState, useEffect } from "react";
+import React, { useEffect } from "react";
import "./editor.css";
import ReactQuill, { Quill } from "react-quill";
import "react-quill/dist/quill.bubble.css";
diff --git a/apps/web/src/components/editor/modules/markdown/index.js b/apps/web/src/components/editor/modules/markdown/index.js
index 66275b2cc..e8efecd10 100644
--- a/apps/web/src/components/editor/modules/markdown/index.js
+++ b/apps/web/src/components/editor/modules/markdown/index.js
@@ -258,7 +258,7 @@ class MarkdownShortcuts {
// remove formatting when there's no text left
if (
delta.ops[0].delete !== undefined &&
- source == "user" &&
+ source === "user" &&
this.quill.getLength() <= 2
) {
this.quill.removeFormat(0, 1);
diff --git a/apps/web/src/components/search/index.js b/apps/web/src/components/search/index.js
new file mode 100644
index 000000000..8ca89029d
--- /dev/null
+++ b/apps/web/src/components/search/index.js
@@ -0,0 +1,36 @@
+import React from "react";
+import { Flex, Box } from "rebass";
+import { Input } from "@rebass/forms";
+import * as Icon from "react-feather";
+import theme, { SHADOW } from "../../theme";
+import "./search.css";
+const Search = props => (
+ <Flex
+ flexDirection="row"
+ justifyContent="center"
+ alignItems="center"
+ sx={{
+ position: "relative"
+ }}
+ >
+ <Input
+ id="searchInput"
+ variant="search"
+ placeholder={props.placeholder}
+ my={2}
+ />
+ <Box
+ id="searchIcon"
+ sx={{
+ position: "absolute",
+ right: 0,
+ marginRight: 10,
+ color: theme.colors["hover"],
+ height: 24
+ }}
+ >
+ <Icon.Search />
+ </Box>
+ </Flex>
+);
+export default Search;
diff --git a/apps/web/src/components/search/search.css b/apps/web/src/components/search/search.css
new file mode 100644
index 000000000..878a0a057
--- /dev/null
+++ b/apps/web/src/components/search/search.css
@@ -0,0 +1,3 @@
+#searchInput:focus + #searchIcon {
+ color: #1790f3;
+}
diff --git a/apps/web/src/index.js b/apps/web/src/index.js
index 48da9f652..bf9a2d18b 100644
--- a/apps/web/src/index.js
+++ b/apps/web/src/index.js
@@ -3,7 +3,9 @@ import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
+import Modal from "react-modal";
+Modal.setAppElement("#root");
ReactDOM.render(<App />, document.getElementById("root"));
// If you want your app to work offline and load faster, you can change
diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.js
index 5525af296..ec2ea3345 100644
--- a/apps/web/src/navigation/index.js
+++ b/apps/web/src/navigation/index.js
@@ -1,6 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";
import Home from "../views/Home";
+import Notebooks from "../views/Notebooks";
import { ThemeProvider } from "emotion-theming";
import { Heading } from "rebass";
import * as Icon from "react-feather";
@@ -16,7 +17,7 @@ export const routes = {
notebooks: {
key: "notebooks",
title: "Notebooks",
- component: undefined,
+ component: Notebooks,
icon: Icon.Book
},
lists: {
diff --git a/apps/web/src/theme.js b/apps/web/src/theme.js
index f1d9dac77..e22b86891 100644
--- a/apps/web/src/theme.js
+++ b/apps/web/src/theme.js
@@ -1,4 +1,10 @@
-export const SHADOW = "0 0 5px 1px #aaaaaa99";
+export const SHADOW = "0 0 8px 0px #aaaaaa44";
+export const DIALOG_SHADOW = "0 0 20px 0px #aaaaaa77";
+export const ButtonPressedStyle = {
+ ":active": {
+ opacity: "0.8"
+ }
+};
export default {
breakpoints: ["480px", "834px", "1200px"],
colors: {
@@ -9,13 +15,15 @@ export default {
//font related
fontPrimary: "black",
fontSecondary: "white",
- border: "#f0f0f0"
+ border: "#f0f0f0",
+ hover: "#e0e0e0"
},
space: [0, 5, 10, 12],
fontSizes: {
heading: 42,
input: 16,
- title: 18,
+ title: 28,
+ subtitle: 18,
body: 14,
menu: 14
},
@@ -35,6 +43,59 @@ export default {
none: 0,
default: 5
},
+ forms: {
+ default: {
+ borderWidth: 0,
+ borderRadius: "default",
+ bg: "primary",
+ border: "2px solid",
+ borderColor: "border",
+ fontFamily: "body",
+ fontWeight: "body",
+ fontSizes: "input",
+ ":focus": {
+ outline: "none",
+ borderColor: "accent"
+ },
+ ":hover": {
+ borderColor: "hover"
+ }
+ },
+ search: {
+ borderWidth: 0,
+ borderRadius: "default",
+ bg: "primary",
+ border: "2px solid",
+ borderColor: "border",
+ fontFamily: "body",
+ fontWeight: "body",
+ fontSizes: "input",
+ ":focus": {
+ outline: "none",
+ boxShadow: SHADOW
+ },
+ ":hover": {
+ borderColor: "hover"
+ }
+ }
+ },
+ text: {
+ heading: {
+ fontFamily: "body",
+ fontWeight: "heading",
+ fontSize: "heading"
+ },
+ title: {
+ fontFamily: "body",
+ fontWeight: "bold",
+ fontSize: "title"
+ },
+ body: {
+ fontFamily: "body",
+ fontWeight: "body",
+ fontSize: "body"
+ }
+ },
buttons: {
nav: {
color: "fontPrimary",
@@ -44,6 +105,44 @@ export default {
":focus": {
outline: "none"
}
+ },
+ primary: {
+ color: "fontSecondary",
+ bg: "accent",
+ borderRadius: "default",
+ fontFamily: "body",
+ fontWeight: "body",
+ ":focus": {
+ outline: "none"
+ },
+ ...ButtonPressedStyle
+ },
+ secondary: {
+ color: "fontPrimary",
+ bg: "navbg",
+ borderRadius: "default",
+ fontFamily: "body",
+ fontWeight: "body",
+ ":focus": {
+ outline: "none"
+ },
+ ...ButtonPressedStyle
+ },
+ tertiary: {
+ color: "fontPrimary",
+ bg: "transparent",
+ borderRadius: "default",
+ border: "2px solid",
+ borderColor: "border",
+ fontFamily: "body",
+ fontWeight: "body",
+ ":focus": {
+ outline: "none"
+ },
+ ":active": {
+ color: "accent",
+ opacity: 0.8
+ }
}
}
};
diff --git a/apps/web/src/views/Home.js b/apps/web/src/views/Home.js
index 2fd14d325..146b89a3f 100644
--- a/apps/web/src/views/Home.js
+++ b/apps/web/src/views/Home.js
@@ -1,8 +1,7 @@
import React, { useEffect, useState } from "react";
import { Flex, Box, Text } from "rebass";
import * as Icon from "react-feather";
-import { SHADOW } from "../theme";
-import { Input } from "@rebass/forms";
+import { ButtonPressedStyle } from "../theme";
import Dropdown, {
DropdownTrigger,
DropdownContent
@@ -13,6 +12,8 @@ import { db, ev } from "../common";
import { Virtuoso as List } from "react-virtuoso";
import { showSnack } from "../components/snackbar";
import Menu from "../components/menu";
+import Button from "../components/button";
+import Search from "../components/search";
const dropdownRefs = [];
const menuItems = [
@@ -52,45 +53,12 @@ function Home() {
}, []);
return (
<Flex flexDirection="column" flex="1 1 auto">
- <Input
- placeholder="Search"
- fontFamily="body"
- fontWeight="body"
- fontSize="input"
- bg="navbg"
- my={2}
- px={3}
- py={3}
- sx={{
- boxShadow: SHADOW,
- borderWidth: 0,
- borderRadius: "default"
- }}
+ <Search placeholder="Search" />
+ <Button
+ Icon={Icon.Plus}
+ content="Make a new note"
+ onClick={sendNewNoteEvent}
/>
- <Flex
- bg="accent"
- width="full"
- py={3}
- px={3}
- flexDirection="row"
- alignItems="center"
- sx={{
- borderRadius: "default",
- marginBottom: 2,
- color: "fontSecondary",
- fontFamily: "body",
- fontWeight: "body",
- ":active": {
- opacity: "0.8"
- }
- }}
- onClick={() => sendNewNoteEvent()}
- >
- <Icon.Plus />
- <Text className="unselectable" mx={1}>
- Make a new note
- </Text>
- </Flex>
<List
style={{ width: "100%", flex: "1 1 auto", height: "auto" }}
totalCount={notes.length}
@@ -101,7 +69,11 @@ function Home() {
bg="navbg"
px={3}
py={3}
- sx={{ borderRadius: "default", marginBottom: 2 }}
+ sx={{
+ borderRadius: "default",
+ marginBottom: 2,
+ ...ButtonPressedStyle
+ }}
>
<Flex flexDirection="row" justifyContent="space-between">
<Text fontFamily="body" fontSize="title" fontWeight="bold">
diff --git a/apps/web/src/views/Notebooks.js b/apps/web/src/views/Notebooks.js
new file mode 100644
index 000000000..35ec32ed0
--- /dev/null
+++ b/apps/web/src/views/Notebooks.js
@@ -0,0 +1,169 @@
+import React, { useState } from "react";
+import { Flex, Box, Text, Button as RebassButton } from "rebass";
+import { Input, Label } from "@rebass/forms";
+import Button from "../components/button";
+import * as Icon from "react-feather";
+import theme, { ButtonPressedStyle, SHADOW, DIALOG_SHADOW } from "../theme";
+import Search from "../components/search";
+import Modal from "react-modal";
+
+const inputRefs = [];
+const notebook = {
+ title: "December",
+ dateCreated: Date.now(),
+ topics: ["Birthday", "Christmas"],
+ totalNotes: 12
+};
+const Notebooks = props => {
+ const [open, setOpen] = useState(false);
+ return (
+ <Flex flexDirection="column">
+ <Search placeholder="Search" />
+ <Button
+ Icon={Icon.Plus}
+ content="Create a notebook"
+ onClick={() => setOpen(true)}
+ />
+ <Flex
+ flexDirection="row"
+ bg={"primary"}
+ py={3}
+ px={3}
+ justifyContent="space-between"
+ alignItems="flex-end"
+ sx={{
+ fontFamily: "body",
+ fontWeight: "body",
+ fontSize: "body",
+ borderRadius: "default",
+ borderBottom: "1px solid",
+ borderBottomColor: "border",
+ ...ButtonPressedStyle
+ }}
+ >
+ <Box>
+ <Text fontSize="title" fontWeight="bold">
+ {notebook.title}
+ </Text>
+ <Text color="accent" fontSize={12}>
+ 12 hours ago
+ </Text>
+ </Box>
+ <Text className="unselectable">{notebook.totalNotes} Notes</Text>
+ </Flex>
+ <CreateNotebookDialog open={open} close={() => setOpen(false)} />
+ </Flex>
+ );
+};
+
+const CreateNotebookDialog = props => {
+ const [topics, setTopics] = useState([""]);
+ const addTopic = index => {
+ topics.splice(index + 1, 0, "");
+ setTopics([...topics]);
+ setTimeout(() => {
+ inputRefs[index + 1].focus();
+ }, 0);
+ };
+ return (
+ <Modal
+ isOpen={props.open}
+ style={{
+ content: {
+ top: "50%",
+ left: "50%",
+ right: "auto",
+ bottom: "auto",
+ marginRight: "-50%",
+ transform: "translate(-50%, -50%)",
+ borderWidth: 0,
+ borderRadius: theme.radii["default"],
+ boxShadow: DIALOG_SHADOW,
+ width: "20%",
+ paddingRight: 40,
+ paddingLeft: 40,
+ overflowY: "hidden"
+ }
+ }}
+ contentLabel="Add a Notebook"
+ >
+ <Flex flexDirection="column">
+ <Flex
+ flexDirection="row"
+ alignItems="center"
+ alignSelf="center"
+ justifyContent="center"
+ color="accent"
+ py={2}
+ >
+ <Icon.BookOpen size={40} />
+ <Text mx={2} as="span" variant="title" textAlign="center">
+ Notebook
+ </Text>
+ </Flex>
+ <Box my={1}>
+ <Input variant="default" placeholder="Enter notebook name" />
+ <Text variant="body" fontWeight="bold" my={1}>
+ Topics (optional):
+ </Text>
+ <Box sx={{ maxHeight: 44 * 5, overflowY: "auto", marginBottom: 1 }}>
+ {topics.map((item, index) => (
+ <Flex flexDirection="row" sx={{ marginBottom: 1 }}>
+ <Input
+ ref={ref => (inputRefs[index] = ref)}
+ variant="default"
+ value={topics[index]}
+ placeholder="Topic name"
+ onFocus={e => {
+ Notebooks.lastLength = e.nativeEvent.target.value.length;
+ }}
+ onChange={e => {
+ topics[index] = e.target.value;
+ setTopics([...topics]);
+ }}
+ onKeyUp={e => {
+ if (e.nativeEvent.key === "Enter") {
+ addTopic(index);
+ } else if (
+ e.nativeEvent.key === "Backspace" &&
+ Notebooks.lastLength === 0 &&
+ index > 0
+ ) {
+ topics.splice(index, 1);
+ setTopics([...topics]);
+ setTimeout(() => {
+ inputRefs[index - 1].focus();
+ }, 0);
+ }
+ Notebooks.lastLength = e.nativeEvent.target.value.length;
+ }}
+ />
+ <RebassButton
+ variant="tertiary"
+ sx={{ marginLeft: 1 }}
+ px={2}
+ py={1}
+ onClick={() => addTopic(index)}
+ >
+ <Box height={20}>
+ <Icon.Plus size={20} />
+ </Box>
+ </RebassButton>
+ </Flex>
+ ))}
+ </Box>
+ </Box>
+ <Flex flexDirection="row" justifyContent="center" alignItems="center">
+ <RebassButton variant="primary" mx={1} onClick={props.close}>
+ Done
+ </RebassButton>
+ <RebassButton variant="secondary" onClick={props.close}>
+ Cancel
+ </RebassButton>
+ </Flex>
+ </Flex>
+ </Modal>
+ );
+};
+
+export default Notebooks;
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 821bab4e0..1c2791198 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -4187,6 +4187,11 @@ execa@^1.0.0:
signal-exit "^3.0.0"
strip-eof "^1.0.0"
+exenv@^1.2.0:
+ version "1.2.2"
+ resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d"
+ integrity sha1-KueOhdmJQVhnCwPUe+wfA72Ru50=
+
exit@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c"
@@ -8618,6 +8623,21 @@ react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.12.0.tgz#2cc0fe0fba742d97fd527c42a13bec4eeb06241c"
integrity sha512-rPCkf/mWBtKc97aLL9/txD8DZdemK0vkA3JMLShjlJB3Pj3s+lpf1KaBzMfQrAmhMQB0n1cU/SUGgKKBCe837Q==
+react-lifecycles-compat@^3.0.0:
+ version "3.0.4"
+ resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
+ integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==
+
+react-modal@^3.11.1:
+ version "3.11.1"
+ resolved "https://registry.yarnpkg.com/react-modal/-/react-modal-3.11.1.tgz#2a0d6877c9e98f123939ea92d2bb4ad7fa5a17f9"
+ integrity sha512-8uN744Yq0X2lbfSLxsEEc2UV3RjSRb4yDVxRQ1aGzPo86QjNOwhQSukDb8U8kR+636TRTvfMren10fgOjAy9eA==
+ dependencies:
+ exenv "^1.2.0"
+ prop-types "^15.5.10"
+ react-lifecycles-compat "^3.0.0"
+ warning "^4.0.3"
+
react-quill@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/react-quill/-/react-quill-1.3.3.tgz#95b8e088ad4e4acc6c79c2f85bdc0460eebe08eb"
@@ -10419,6 +10439,13 @@ walker@^1.0.7, walker@~1.0.5:
dependencies:
makeerror "1.0.x"
+warning@^4.0.3:
+ version "4.0.3"
+ resolved "https://registry.yarnpkg.com/warning/-/warning-4.0.3.tgz#16e9e077eb8a86d6af7d64aa1e05fd85b4678ca3"
+ integrity sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==
+ dependencies:
+ loose-envify "^1.0.0"
+
watchpack@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.6.0.tgz#4bc12c2ebe8aa277a71f1d3f14d685c7b446cd00"