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 add notebook
thecodrr9063d76107cb
diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex db72cd94c..c86dc2dfb 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/views/Home.js b/apps/web/src/views/Home.jsindex 6a455be7b..c3f32bc6b 100644--- a/apps/web/src/views/Home.js+++ b/apps/web/src/views/Home.js@@ -26,10 +26,10 @@ const menuItems = [ev.emit("onClearNote", note.dateCreated);db.deleteNotes([note]).then(//TODO implement undo- async () => {+ () => {showSnack("Note deleted!", Icon.Check);//TODO very crude but works.- await Home.onRefresh();+ Home.onRefresh();});}@@ -45,8 +45,8 @@ function sendOpenNoteEvent(note) {function Home() {const [notes, setNotes] = useState([]);useEffect(() => {- Home.onRefresh = async () => {- setNotes(await db.getNotes());+ Home.onRefresh = () => {+ setNotes(db.getNotes());};Home.onRefresh();return () => {@@ -59,7 +59,12 @@ function Home() {<Flex flexDirection="column" flex="1 1 auto"><Search placeholder="Search" /><List- style={{ width: "100%", flex: "1 1 auto", height: "auto" }}+ style={{+ width: "100%",+ flex: "1 1 auto",+ height: "auto",+ overflowX: "hidden"+ }}totalCount={notes.length}item={index => {const note = notes[index];@@ -69,7 +74,6 @@ function Home() {sendOpenNoteEvent(note);e.stopPropagation();}}- px={3}py={3}sx={{borderRadius: "default",diff --git a/apps/web/src/views/Notebooks.js b/apps/web/src/views/Notebooks.jsindex 6c2d8e45c..990da81a1 100644--- a/apps/web/src/views/Notebooks.js+++ b/apps/web/src/views/Notebooks.js@@ -1,4 +1,4 @@-import React, { useState } from "react";+import React, { useState, useEffect } from "react";import { Flex, Box, Text, Button as RebassButton } from "rebass";import { Input, Label } from "@rebass/forms";import Button from "../components/button";@@ -6,53 +6,173 @@ import * as Icon from "react-feather";import theme, { ButtonPressedStyle, SHADOW, DIALOG_SHADOW } from "../theme";import Search from "../components/search";import Modal from "react-modal";+import { db, ev } from "../common";+import { showSnack } from "../components/snackbar";+import { Virtuoso as List } from "react-virtuoso";+import Dropdown, {+ DropdownTrigger,+ DropdownContent+} from "../components/dropdown";+import Menu from "../components/menu";const inputRefs = [];-const notebook = {- title: "December",- dateCreated: Date.now(),- topics: ["Birthday", "Christmas"],- totalNotes: 12-};+const dropdownRefs = [];+const menuItems = [+ { title: "Favorite", icon: Icon.Heart },+ { title: "Share", icon: Icon.Share2 },+ {+ title: "Delete",+ icon: Icon.Trash,+ color: "red",+ onClick: note => {+ ev.emit("onClearNote", note.dateCreated);+ db.deleteNotes([note]).then(+ //TODO implement undo+ async () => {+ showSnack("Note deleted!", Icon.Check);+ }+ );+ }+ }+];+const Notebooks = props => {const [open, setOpen] = useState(false);+ const [notebooks, setNotebooks] = useState([]);+ useEffect(() => {+ Notebooks.onRefresh = () => {+ setNotebooks(db.getNotebooks());+ console.log(notebooks);+ };+ Notebooks.onRefresh();+ return () => {+ Notebooks.onRefresh = undefined;+ };+ }, []);return (- <Flex flexDirection="column">- <Search placeholder="Search" />- <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+ <Flex flexDirection="column" flex="1 1 auto">+ {notebooks.length > 0 ? (+ <Flex flexDirection="column" flex="1 1 auto">+ <Search placeholder="Search" />+ <List+ style={{+ width: "100%",+ flex: "1 1 auto",+ height: "auto",+ overflowX: "hidden"+ }}+ totalCount={notebooks.length}+ item={index => {+ const notebook = notebooks[index];+ return (+ <Box+ onClick={e => {+ e.stopPropagation();+ }}+ py={1}+ sx={{+ borderRadius: "default",+ marginBottom: 2,+ borderBottom: "1px solid",+ borderBottomColor: "navbg",+ cursor: "default",+ ...ButtonPressedStyle+ }}+ >+ <Flex flexDirection="row" justifyContent="space-between">+ <Text fontFamily="body" fontSize="title" fontWeight="bold">+ {notebook.title}+ </Text>+ <Dropdown+ style={{ zIndex: 999 }}+ ref={ref => (dropdownRefs[index] = ref)}+ >+ <DropdownTrigger>+ <Icon.MoreVertical+ size={20}+ strokeWidth={1.5}+ style={{ marginRight: -5 }}+ />+ </DropdownTrigger>+ <DropdownContent style={{ zIndex: 999, marginLeft: -70 }}>+ <Menu+ dropdownRef={dropdownRefs[index]}+ menuItems={menuItems}+ data={notebook}+ />+ </DropdownContent>+ </Dropdown>+ </Flex>+ <Text variant="body" sx={{ marginBottom: 1 }}>+ {notebook.description}+ </Text>+ <Flex sx={{ marginBottom: 1 }}>+ {Object.keys(notebook.topics)+ .slice(0, 3)+ .map(topic => (+ <Flex+ bg="accent"+ px={1}+ py={1}+ sx={{+ marginRight: 1,+ borderRadius: "default",+ color: "fontSecondary"+ }}+ >+ <Text variant="body" fontSize={11}>+ {topic}+ </Text>+ </Flex>+ ))}+ </Flex>+ <Text variant="body" fontSize={12} color="accent">+ {new Date(notebook.dateCreated).toDateString().substring(4)}+ <Text as="span" color="fontPrimary">+ {" • " + notebook.totalNotes} Notes+ </Text>+ </Text>+ </Box>+ );+ }}+ />+ <Button+ Icon={Icon.Plus}+ onClick={() => setOpen(true)}+ content="Create a notebook"+ />+ </Flex>+ ) : (+ <Flex+ flex="1 1 auto"+ alignItems="center"+ justifyContent="center"+ color="#9b9b9b"+ flexDirection="column"+ >+ <Icon.Book size={72} strokeWidth={1.5} />+ <Text variant="title">You have no notebooks</Text>+ <Button+ Icon={Icon.Plus}+ content="Let's create one"+ onClick={() => setOpen(true)}+ style={{ marginTop: 2, textAlign: "center" }}+ width={"auto"}+ />+ </Flex>+ )}+ <CreateNotebookDialog+ open={open}+ onDone={async (topics, title, description) => {+ if (await db.addNotebook({ title, description, topics })) {+ setNotebooks(db.getNotebooks());+ setOpen(false);+ } else {+ showSnack("Please fill out the notebook title.");+ }}}- >- <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>-- <Button- Icon={Icon.Plus}- content="Create a notebook"- onClick={() => setOpen(true)}+ close={() => setOpen(false)}/>- <CreateNotebookDialog open={open} close={() => setOpen(false)} /></Flex>);};@@ -109,13 +229,27 @@ const CreateNotebookDialog = props => {</Text></Flex><Box my={1}>- <Input variant="default" placeholder="Enter notebook name" />+ <Input+ variant="default"+ onChange={e => (CreateNotebookDialog.title = e.target.value)}+ placeholder="Enter name"+ />+ <Input+ variant="default"+ sx={{ marginTop: 1 }}+ onChange={e => (CreateNotebookDialog.description = e.target.value)}+ placeholder="Enter description (optional)"+ /><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 }}>+ <Flex+ key={item + index.toString()}+ flexDirection="row"+ sx={{ marginBottom: 1 }}+ ><Inputref={ref => (inputRefs[index] = ref)}variant="default"@@ -161,7 +295,17 @@ const CreateNotebookDialog = props => {</Box></Box><Flex flexDirection="row" justifyContent="center" alignItems="center">- <RebassButton variant="primary" mx={1} onClick={props.close}>+ <RebassButton+ variant="primary"+ mx={1}+ onClick={() =>+ props.onDone(+ topics,+ CreateNotebookDialog.title,+ CreateNotebookDialog.description+ )+ }+ >Done</RebassButton><RebassButton variant="secondary" onClick={props.close}>