Skip to content

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

feat: implement properties fully

thecodrr939fc3647668
diff --git a/apps/web/src/app.css b/apps/web/src/app.css
index ba5f77b2f..534c6d07f 100644
--- a/apps/web/src/app.css
+++ b/apps/web/src/app.css
@@ -5,7 +5,6 @@
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
- cursor: default;
outline: none;
}
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index a385cf928..7f05c6531 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -5,7 +5,6 @@ import { Flex, Box, Button } from "rebass";
import { ThemeProvider } from "./utils/theme";
import RootNavigator from "./navigation/navigators/rootnavigator";
import "./app.css";
-import Properties from "./views/Properties";
const NavMenuItem = props => {
return (
@@ -116,7 +115,6 @@ function App() {
}}
/>
<Editor />
- <Properties />
</Flex>
<Box id="dialogContainer" />
<Box id="snackbarContainer" />
diff --git a/apps/web/src/components/checkbox/index.js b/apps/web/src/components/checkbox/index.js
index 021d64299..60e039314 100644
--- a/apps/web/src/components/checkbox/index.js
+++ b/apps/web/src/components/checkbox/index.js
@@ -1,15 +1,19 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import { Flex, Text } from "rebass";
+import { Switch } from "@rebass/forms";
import * as Icon from "react-feather";
const CheckBox = props => {
- const [checked, setChecked] = useState(props.checked);
+ const [checked, setChecked] = useState(props.checked || false);
+ useEffect(() => {
+ setChecked(props.checked);
+ }, [props.checked]);
return (
<Flex
onClick={() => {
setChecked(!checked);
- if (props.onCheckChanged) {
- props.onCheckChanged(checked);
+ if (props.onChecked) {
+ props.onChecked(!checked);
}
}}
width="full"
@@ -21,9 +25,8 @@ const CheckBox = props => {
<props.icon size={18} />
<Text sx={{ marginLeft: 1 }}>{props.label}</Text>
</Flex>
- <Text color={checked ? "primary" : "foreground"}>
- <Icon.CheckCircle size={18} style={{ cursor: "pointer" }} />
- </Text>
+
+ <Switch checked={checked} />
</Flex>
);
};
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 1f261c46b..15946bc16 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -10,7 +10,7 @@ import MagicUrl from "quill-magic-url";
import { db, ev } from "../../common";
import { showSnack } from "../snackbar";
import * as Icon from "react-feather";
-import Properties from "../properties/properties";
+import Properties from "../properties";
Quill.register("modules/markdownShortcuts", MarkdownShortcuts);
Quill.register("modules/magicUrl", MagicUrl);
@@ -45,6 +45,18 @@ export default class Editor extends React.Component {
title = "";
timeout = "";
timestamp = "";
+ favorite = false;
+ pinned = false;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ pinned: false,
+ favorite: false,
+ colors: [],
+ tags: []
+ };
+ }
componentDidMount() {
// move the toolbar outside (easiest way)
@@ -103,6 +115,13 @@ export default class Editor extends React.Component {
this.timestamp = note.dateCreated;
this.title = note.title;
this.titleRef.value = note.title;
+ this.pinned = note.pinned;
+ this.favorite = note.favorite;
+ this.setState({
+ pinned: this.pinned,
+ favorite: this.favorite,
+ colors: note.colors
+ });
this.quill.setContents(note.content.delta);
this.quill.setSelection(note.content.text.length - 1, 0); //to move the cursor to the end
});
@@ -113,18 +132,28 @@ export default class Editor extends React.Component {
delta: this.quill.getContents(),
text: this.quill.getText()
};
- if (!content.delta || content.text.length <= 1) return this.timestamp;
+ if (!this.title && (!content.delta || content.text.length <= 1))
+ return this.timestamp;
let note = {
content,
title: this.title,
- dateCreated: this.timestamp
+ dateCreated: this.timestamp,
+ favorite: this.favorite,
+ pinned: this.pinned,
+ colors: this.state.colors
+ //TODO add tags once the database is done
};
let t = await db.addNote(note);
-
- console.log(t);
return t;
}
+ save() {
+ clearTimeout(this.timeout);
+ this.timeout = setTimeout(async () => {
+ this.timestamp = await this.saveNote();
+ }, 1000);
+ }
+
render() {
return (
<Flex width={["0%", "50%", "75%"]}>
@@ -150,7 +179,10 @@ export default class Editor extends React.Component {
paddingBottom: 3
}}
px={2}
- onChange={e => (this.title = e.target.value)}
+ onChange={e => {
+ this.title = e.target.value;
+ this.save();
+ }}
/>
<Box id="toolbar" display={["none", "flex", "flex"]}></Box>
<ReactQuill
@@ -158,17 +190,42 @@ export default class Editor extends React.Component {
modules={modules}
theme="snow"
onChange={() => {
- clearTimeout(this.timeout);
- this.timeout = setTimeout(async () => {
- this.timestamp = await this.saveNote();
- console.log(this.timestamp);
- }, 1000);
+ this.save();
}}
/>
</Flex>
<Properties
- onPinned={state => {}}
- onFavorited={state => {}}
+ pinned={this.state.pinned}
+ favorite={this.state.favorite}
+ onPinned={state => {
+ this.pinned = state;
+ this.save();
+ }}
+ onFavorited={state => {
+ this.favorite = state;
+ this.save();
+ }}
+ selectedColors={this.state.colors}
+ colorSelected={color => {
+ if (this.state.colors.includes(color.label)) {
+ this.state.colors.splice(
+ this.state.colors.indexOf(color.label),
+ 1
+ );
+ } else {
+ this.state.colors[this.state.colors.length] = color.label;
+ }
+ this.setState({ colors: this.state.colors });
+ }}
+ tags={this.state.tags}
+ addTag={tag => {
+ if (this.state.tags.includes(tag)) {
+ this.state.tags.splice(this.state.tags.indexOf(tag), 1);
+ } else {
+ this.state.tags[this.state.tags.length] = tag;
+ }
+ this.setState({ tags: this.state.tags });
+ }}
onLocked={state => {}}
/>
</Flex>
diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.js
new file mode 100644
index 000000000..c73c48262
--- /dev/null
+++ b/apps/web/src/components/icons/index.js
@@ -0,0 +1,17 @@
+import React from "react";
+
+export const PinIcon = ({ size }) => (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width={size}
+ height={size}
+ viewBox={`0 0 24 24`}
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ >
+ <path d="M17.85 10.2l-4.24 5.65m4.24-5.66L13.6 5.95m4.24 4.24a2 2 0 0 0 2.83 0l.7-.7-7.07-7.08-.7.71a2 2 0 0 0 0 2.83m0 9.9l-5.66-5.66m5.66 5.66s1.76 2.47-.71 4.95L3 10.9c2.47-2.48 4.95-.7 4.95-.7m0 0l5.66-4.25M7.95 15.85l-4.24 4.24" />
+ </svg>
+);
diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.js
new file mode 100644
index 000000000..23a1bfcd5
--- /dev/null
+++ b/apps/web/src/components/properties/index.js
@@ -0,0 +1,114 @@
+import React from "react";
+import * as Icon from "react-feather";
+import { Flex, Box, Text } from "rebass";
+import { Input } from "@rebass/forms";
+import CheckBox from "../checkbox";
+import { PinIcon } from "../icons";
+
+const Properties = props => {
+ return (
+ <Flex
+ sx={{ borderLeft: "1px solid", borderColor: "border", width: "25%" }}
+ flexDirection="column"
+ bg="shade"
+ px={3}
+ py={3}
+ >
+ <Text variant="title" color="primary" my={2}>
+ Properties
+ </Text>
+ <CheckBox
+ checked={props.pinned}
+ icon={PinIcon}
+ label="Pin"
+ onChecked={props.onPinned}
+ />
+ <CheckBox
+ icon={Icon.Star}
+ checked={props.favorite}
+ label="Favorite"
+ onChecked={props.onFavorited}
+ />
+ <CheckBox icon={Icon.Lock} label="Lock" onChecked={props.onLocked} />
+ <Flex fontSize="body" sx={{ marginBottom: 2 }} alignItems="center">
+ <Icon.Tag size={18} />
+ <Text sx={{ marginLeft: 1 }}>Tags:</Text>
+ </Flex>
+ <Input
+ variant="default"
+ placeholder="#tag"
+ sx={{ marginBottom: 2 }}
+ onKeyUp={e => {
+ if (e.key === "Enter" || e.key === " " || e.key === ",") {
+ props.addTag && props.addTag(e.target.value);
+ e.target.value = "";
+ }
+ }}
+ />
+ <Flex
+ fontSize="body"
+ sx={{ marginBottom: 2 }}
+ alignItems="center"
+ justifyContent="flex-start"
+ flexWrap="wrap"
+ >
+ {props.tags &&
+ props.tags.map(v => (
+ <Text
+ sx={{
+ backgroundColor: "primary",
+ color: "static",
+ borderRadius: "default",
+ padding: "2px 5px 2px 5px",
+ marginBottom: 1,
+ marginRight: 1
+ }}
+ >
+ #{v}
+ </Text>
+ ))}
+ </Flex>
+ <Flex fontSize="body" sx={{ marginBottom: 2 }} alignItems="center">
+ <Icon.Octagon size={18} />
+ <Text sx={{ marginLeft: 1 }}>Colors:</Text>
+ </Flex>
+ <Flex flexWrap="wrap" sx={{ marginBottom: 2 }}>
+ {[
+ { label: "red", code: "#ed2d37" },
+ { label: "orange", code: "#ec6e05" },
+ { label: "yellow", code: "yellow" },
+ { label: "green", code: "green" },
+ { label: "blue", code: "blue" },
+ { label: "purple", code: "purple" },
+ { label: "gray", code: "gray" }
+ ].map(color => (
+ <Flex
+ sx={{ position: "relative" }}
+ justifyContent="center"
+ alignItems="center"
+ onClick={() => props.colorSelected && props.colorSelected(color)}
+ >
+ <Icon.Circle
+ size={40}
+ style={{ cursor: "pointer" }}
+ fill={color.code}
+ strokeWidth={0}
+ />
+ {props.selectedColors &&
+ props.selectedColors.includes(color.label) && (
+ <Icon.Check
+ style={{
+ position: "absolute",
+ color: "white"
+ }}
+ size={20}
+ />
+ )}
+ </Flex>
+ ))}
+ </Flex>
+ </Flex>
+ );
+};
+
+export default Properties;
diff --git a/apps/web/src/views/Properties.js b/apps/web/src/views/Properties.js
deleted file mode 100644
index 497573cff..000000000
--- a/apps/web/src/views/Properties.js
+++ /dev/null
@@ -1,52 +0,0 @@
-import React from "react";
-import * as Icon from "react-feather";
-import { Flex, Box, Text } from "rebass";
-import { Input } from "@rebass/forms";
-import CheckBox from "../components/checkbox";
-
-function Properties() {
- return (
- <Flex
- sx={{ borderLeft: "1px solid", borderColor: "border" }}
- flexDirection="column"
- bg="shade"
- flex="1 1 auto"
- px={2}
- py={2}
- width={["0%", "0%", "10%"]}
- >
- <Text variant="title" color="primary" my={2}>
- Properties
- </Text>
- <CheckBox icon={Icon.MapPin} label="Pin" />
- <CheckBox icon={Icon.Star} label="Favorite" />
- <CheckBox icon={Icon.Lock} label="Lock" />
- <Flex fontSize="body" sx={{ marginBottom: 2 }} alignItems="center">
- <Icon.Tag size={18} />
- <Text sx={{ marginLeft: 1 }}>Tags:</Text>
- </Flex>
- <Input sx={{ marginBottom: 2 }} variant="default" />
- <Flex fontSize="body" sx={{ marginBottom: 2 }} alignItems="center">
- <Icon.Octagon size={18} />
- <Text sx={{ marginLeft: 1 }}>Colors:</Text>
- </Flex>
- <Flex flexWrap="wrap" sx={{ marginBottom: 2 }}>
- {[
- { label: "red", code: "#ed2d37" },
- { label: "orange", code: "#ec6e05" },
- { label: "yellow", code: "yellow" },
- { label: "green", code: "green" },
- { label: "blue", code: "blue" },
- { label: "purple", code: "purple" },
- { label: "gray", code: "gray" }
- ].map(color => (
- <Box sx={{ cursor: "pointer" }}>
- <Icon.Circle size={40} fill={color.code} strokeWidth={0} />
- </Box>
- ))}
- </Flex>
- </Flex>
- );
-}
-
-export default Properties;