Skip to content

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

feat: render notes from database

thecodrrdbfe6105bff9
diff --git a/apps/web/package.json b/apps/web/package.json
index 54db87b75..9597d48a7 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -16,7 +16,8 @@
"react-quill": "^1.3.3",
"react-scripts": "3.2.0",
"react-simple-dropdown": "^3.2.3",
- "rebass": "^4.0.7"
+ "rebass": "^4.0.7",
+ "timeago-react": "^3.0.0"
},
"devDependencies": {
"babel-loader": "8.0.6"
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 4e4367baa..220b89b0c 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -47,7 +47,7 @@ async function saveNote(quill) {
text: quill.getText()
},
title,
- timestamp
+ dateCreated: timestamp
};
timestamp = await db.addNote(note);
}
diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.js
index 4d8da9cd1..5525af296 100644
--- a/apps/web/src/navigation/index.js
+++ b/apps/web/src/navigation/index.js
@@ -57,7 +57,7 @@ export function navigate(routeName, root = "navigationView") {
let rootView = document.querySelector(`.${root}`);
if (!rootView) return;
- ReactDOM.render(getThemedComponent(route), rootView);
+ ReactDOM.render(<ThemedComponent route={route} />, rootView);
historyContainer[historyContainer.length] = {
...route
@@ -73,15 +73,15 @@ export function goBack(root) {
if (route) {
let rootView = document.querySelector(`.${root}`);
if (!rootView) return;
- ReactDOM.render(getThemedComponent(route), rootView);
+ ReactDOM.render(<ThemedComponent route={route} />, rootView);
}
}
-function getThemedComponent(route) {
+function ThemedComponent(props) {
return (
<ThemeProvider theme={theme}>
- <Heading fontSize="heading">{route.title}</Heading>
- {route.component && route.component()}
+ <Heading fontSize="heading">{props.route.title}</Heading>
+ {props.route.component && props.route.component()}
</ThemeProvider>
);
}
diff --git a/apps/web/src/views/Home.js b/apps/web/src/views/Home.js
index 55d8fa97f..272e6dbcb 100644
--- a/apps/web/src/views/Home.js
+++ b/apps/web/src/views/Home.js
@@ -1,4 +1,4 @@
-import React, { useEffect } from "react";
+import React, { useEffect, useState } from "react";
import { Flex, Box, Text, Heading } from "rebass";
import * as Icon from "react-feather";
import { SHADOW } from "../theme";
@@ -7,7 +7,9 @@ import Dropdown, {
DropdownTrigger,
DropdownContent
} from "react-simple-dropdown";
+import TimeAgo from "timeago-react";
import "react-simple-dropdown/styles/Dropdown.css";
+import { db } from "../common";
const menuItems = [
{ title: "Favorite", icon: Icon.Heart },
@@ -58,6 +60,10 @@ function NoteMenu() {
}
function Home() {
+ const [notes, setNotes] = useState([]);
+ useEffect(async () => {
+ setNotes(await db.getNotes());
+ }, []);
return (
<Box>
<Input
@@ -75,32 +81,38 @@ function Home() {
borderRadius: "default"
}}
/>
- <Box bg="navbg" px={3} py={3} sx={{ borderRadius: "default" }}>
- <Flex flexDirection="row" justifyContent="space-between">
- <Text fontFamily="body" fontSize="title" fontWeight="bold">
- This is a note title
+ {notes.map(note => (
+ <Box bg="navbg" px={3} py={3} sx={{ borderRadius: "default" }}>
+ <Flex flexDirection="row" justifyContent="space-between">
+ <Text fontFamily="body" fontSize="title" fontWeight="bold">
+ {note.title}
+ </Text>
+ <Dropdown ref={ref => (notesMenu = ref)}>
+ <DropdownTrigger>
+ <Icon.MoreVertical
+ size={20}
+ strokeWidth={1.5}
+ style={{ marginRight: -5 }}
+ />
+ </DropdownTrigger>
+ <DropdownContent style={{ zIndex: 999, marginLeft: -70 }}>
+ <NoteMenu />
+ </DropdownContent>
+ </Dropdown>
+ </Flex>
+ <Text fontFamily="body" fontSize="body" sx={{ marginTop: 1 }}>
+ {note.headline}
</Text>
- <Dropdown ref={ref => (notesMenu = ref)}>
- <DropdownTrigger>
- <Icon.MoreVertical
- size={20}
- strokeWidth={1.5}
- style={{ marginRight: -5 }}
- />
- </DropdownTrigger>
- <DropdownContent style={{ zIndex: 999, marginLeft: -70 }}>
- <NoteMenu />
- </DropdownContent>
- </Dropdown>
- </Flex>
- <Text fontFamily="body" fontSize="body" sx={{ marginTop: 1 }}>
- You are born to be the greatest there ever was. Embrace your true
- powers!
- </Text>
- <Text fontFamily="body" fontWeight="body" fontSize={12} color="accent">
- 5 hours ago
- </Text>
- </Box>
+ <Text
+ fontFamily="body"
+ fontWeight="body"
+ fontSize={12}
+ color="accent"
+ >
+ <TimeAgo datetime={note.dateCreated} />
+ </Text>
+ </Box>
+ ))}
</Box>
);
}
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index a5ecb97fc..cb4e36193 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -10049,6 +10049,18 @@ thunky@^1.0.2:
resolved "https://registry.yarnpkg.com/thunky/-/thunky-1.1.0.tgz#5abaf714a9405db0504732bbccd2cedd9ef9537d"
integrity sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==
+timeago-react@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/timeago-react/-/timeago-react-3.0.0.tgz#777665f768ae0517e71be137fc6287c4d0a6a788"
+ integrity sha512-dO7dBjuRqUSoyt7kLc6UJLvfN5F0JbC2qTqIsjpRFaMXu9bK9PKuWQ3/XD/kPZWGVtwpNimKDpQC3Q2ok8MMSA==
+ dependencies:
+ timeago.js "^4.0.0"
+
+timeago.js@^4.0.0:
+ version "4.0.1"
+ resolved "https://registry.yarnpkg.com/timeago.js/-/timeago.js-4.0.1.tgz#4be4aa19565ceaeb0da31fe14e01ce6ca4742da6"
+ integrity sha512-ePzZuMoJqUc44hJbUYtY1qtzU7IammxooDCcFKogLkS5Nj+iCabR0ZlmNOFX8Dm1r5EpvR5q/PotOJli/mEPew==
+
timers-browserify@^2.0.4:
version "2.0.11"
resolved "https://registry.yarnpkg.com/timers-browserify/-/timers-browserify-2.0.11.tgz#800b1f3eee272e5bc53ee465a04d0e804c31211f"