Skip to content

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

refactor: make all views child of ListContainer comp.

thecodrr04b9302ad312
diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.js
new file mode 100644
index 000000000..17455db7a
--- /dev/null
+++ b/apps/web/src/components/list-container/index.js
@@ -0,0 +1,33 @@
+import React from "react";
+import { Flex } from "rebass";
+import Button from "../button";
+import Search from "../search";
+import * as Icon from "react-feather";
+import { Virtuoso as List } from "react-virtuoso";
+
+const ListContainer = props => {
+ return (
+ <Flex flexDirection="column" flex="1 1 auto">
+ <Search placeholder="Search" />
+ <List
+ style={{
+ width: "100%",
+ flex: "1 1 auto",
+ height: "auto",
+ overflowX: "hidden"
+ }}
+ totalCount={props.itemLength}
+ item={props.item}
+ />
+ {props.button && (
+ <Button
+ Icon={props.button.icon || Icon.Plus}
+ content={props.button.content}
+ onClick={props.button.onClick}
+ />
+ )}
+ </Flex>
+ );
+};
+
+export default ListContainer;
diff --git a/apps/web/src/components/listview/index.js b/apps/web/src/components/listview/index.js
index 8d279cb4f..dab5095f3 100644
--- a/apps/web/src/components/listview/index.js
+++ b/apps/web/src/components/listview/index.js
@@ -4,9 +4,7 @@ import Button from "../button";
import { ev } from "../../common";
import ListItem from "../list-item";
import TimeAgo from "timeago-react";
-import Search from "../search";
-import * as Icon from "react-feather";
-import { Virtuoso as List } from "react-virtuoso";
+import ListContainer from "../list-container";
function ListView({ type, getItems, menu, button }) {
const [items, setItems] = useState([]);
@@ -21,73 +19,36 @@ function ListView({ type, getItems, menu, button }) {
ev.removeListener(`refresh${type}`, onRefreshItems);
};
}, [getItems, type]);
-
return (
- <Flex flexDirection="column" flex="1 1 auto">
- {items.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={items.length}
- item={index => {
- const item = items[index];
- return (
- <ListItem
- title={item.title}
- body={item.headline}
- index={index}
- onClick={() => {}} //TODO
- info={
- <Flex justifyContent="center" alignItems="center">
- <TimeAgo
- datetime={item.dateDeleted || item.dateCreated}
- />
- <Text as="span" mx={1}>
- •
- </Text>
- <Text color="primary">
- {item.type[0].toUpperCase() + item.type.substring(1)}
- </Text>
- </Flex>
- }
- menuData={item}
- menuItems={menu.menuItems(item)}
- dropdownRefs={menu.dropdownRefs}
- />
- );
- }}
+ <ListContainer
+ itemsLength={items.length}
+ item={index => {
+ const item = items[index];
+ return (
+ <ListItem
+ title={item.title}
+ body={item.headline}
+ index={index}
+ onClick={() => {}} //TODO
+ info={
+ <Flex justifyContent="center" alignItems="center">
+ <TimeAgo datetime={item.dateDeleted || item.dateCreated} />
+ <Text as="span" mx={1}>
+ •
+ </Text>
+ <Text color="primary">
+ {item.type[0].toUpperCase() + item.type.substring(1)}
+ </Text>
+ </Flex>
+ }
+ menuData={item}
+ menuItems={menu.menuItems(item)}
+ dropdownRefs={menu.dropdownRefs}
/>
- {button && (
- <Button
- Icon={button.icon}
- content={button.callToAction}
- onClick={button.onClick}
- />
- )}
- </Flex>
- ) : (
- <Flex
- flex="1 1 auto"
- alignItems="center"
- justifyContent="center"
- color="#9b9b9b"
- flexDirection="column"
- >
- {type === "Favorites" ? (
- <Icon.Star size={72} strokeWidth={1.5} />
- ) : (
- <Icon.Trash size={72} strokeWidth={1.5} />
- )}
- <Text variant="title">You have no {type}.</Text>
- </Flex>
- )}
- </Flex>
+ );
+ }}
+ button={button}
+ />
);
}
diff --git a/apps/web/src/navigation/navigators/nbnavigator.js b/apps/web/src/navigation/navigators/nbnavigator.js
new file mode 100644
index 000000000..87503459c
--- /dev/null
+++ b/apps/web/src/navigation/navigators/nbnavigator.js
@@ -0,0 +1,15 @@
+import Notebooks from "../../views/Notebooks";
+import Topics from "../../views/Topics";
+import Notes from "../../views/Notes";
+import Navigator from "../index";
+import { createRoute } from "../routes";
+
+const routes = {
+ ...createRoute("notebooks", Notebooks, { title: "Notebooks" }),
+ ...createRoute("topics", Topics),
+ ...createRoute("notes", Notes)
+};
+const NotebookNavigator = new Navigator("NotebookNavigator", routes, {
+ backButtonEnabled: true
+});
+export default NotebookNavigator;
diff --git a/apps/web/src/views/Notebooks.js b/apps/web/src/views/Notebooks.js
index 1bdf0baf0..e856a922c 100644
--- a/apps/web/src/views/Notebooks.js
+++ b/apps/web/src/views/Notebooks.js
@@ -1,17 +1,11 @@
import React, { useState, useEffect } from "react";
-import { Flex, Text } from "rebass";
-import Button from "../components/button";
-import * as Icon from "react-feather";
-import Search from "../components/search";
+import { Flex } from "rebass";
import { db, ev } from "../common";
import { showSnack } from "../components/snackbar";
-import { Virtuoso as List } from "react-virtuoso";
import Notebook from "../components/notebook";
-import Topics from "./Topics";
-import Notes from "./Notes";
-import { createRoute } from "../navigation/routes";
-import Navigator from "../navigation";
import { CreateNotebookDialog, ask } from "../components/dialogs";
+import ListContainer from "../components/list-container";
+import NotebookNavigator from "../navigation/navigators/nbnavigator";
const NotebooksView = props => {
const [open, setOpen] = useState(false);
@@ -29,40 +23,30 @@ const NotebooksView = props => {
}, []);
return (
- <Flex flexDirection="column" flex="1 1 auto">
- <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 => (
- <Notebook
- index={index}
- item={notebooks[index]}
- onClick={() => {
- NotebookNavigator.navigate("topics", {
- title: notebooks[index].title,
- topics: notebooks[index].topics,
- notebookId: notebooks[index].dateCreated
- });
- }}
- /* onTopicClick={(notebook, topic) =>
+ <>
+ <ListContainer
+ itemsLength={notebooks.length}
+ item={index => (
+ <Notebook
+ index={index}
+ item={notebooks[index]}
+ onClick={() => {
+ NotebookNavigator.navigate("topics", {
+ title: notebooks[index].title,
+ topics: notebooks[index].topics,
+ notebookId: notebooks[index].dateCreated
+ });
+ }}
+ /* onTopicClick={(notebook, topic) =>
navigate(topic, true, notebook.title)
} */
- />
- )}
- />
- <Button
- Icon={Icon.Plus}
- onClick={async () => setOpen(true)}
- content="Create a notebook"
- />
- </Flex>
+ />
+ )}
+ button={{
+ content: "Create a notebook",
+ onClick: async () => setOpen(true)
+ }}
+ />
<CreateNotebookDialog
open={open}
onDone={async (topics, title, description) => {
@@ -75,7 +59,7 @@ const NotebooksView = props => {
}}
close={() => setOpen(false)}
/>
- </Flex>
+ </>
);
};
@@ -93,13 +77,3 @@ const Notebooks = props => {
};
export default Notebooks;
-
-const routes = {
- ...createRoute("notebooks", NotebooksView, { title: "Notebooks" }),
- ...createRoute("topics", Topics),
- ...createRoute("notes", Notes)
-};
-const NotebookNavigator = new Navigator("NotebookNavigator", routes, {
- backButtonEnabled: true
-});
-export { NotebookNavigator };
diff --git a/apps/web/src/views/Notes.js b/apps/web/src/views/Notes.js
index 1d4821bc1..3b42d9831 100644
--- a/apps/web/src/views/Notes.js
+++ b/apps/web/src/views/Notes.js
@@ -1,32 +1,19 @@
import React from "react";
-import { Flex } from "rebass";
-import Button from "../components/button";
import * as Icon from "react-feather";
-import Search from "../components/search";
-import { Virtuoso as List } from "react-virtuoso";
import Note from "../components/note";
import { sendNewNoteEvent } from "../common";
+import ListContainer from "../components/list-container";
const Notes = props => {
return (
- <Flex flexDirection="column" flex="1 1 auto">
- <Search placeholder="Search" />
- <List
- style={{
- width: "100%",
- flex: "1 1 auto",
- height: "auto",
- overflowX: "hidden"
- }}
- totalCount={props.notes.length}
- item={index => <Note index={index} item={props.notes[index]} />}
- />
- <Button
- Icon={Icon.Plus}
- content="Make a new note"
- onClick={sendNewNoteEvent}
- />
- </Flex>
+ <ListContainer
+ item={index => <Note index={index} item={props.notes[index]} />}
+ itemsLength={props.notes.length}
+ button={{
+ content: "Make a new note",
+ onClick: sendNewNoteEvent
+ }}
+ />
);
};
diff --git a/apps/web/src/views/Topics.js b/apps/web/src/views/Topics.js
index 198d1d603..2768f5b26 100644
--- a/apps/web/src/views/Topics.js
+++ b/apps/web/src/views/Topics.js
@@ -1,41 +1,30 @@
-import React, { useEffect } from "react";
-import { Flex } from "rebass";
-import Button from "../components/button";
-import * as Icon from "react-feather";
-import Search from "../components/search";
-import { Virtuoso as List } from "react-virtuoso";
-import { NotebookNavigator } from "./Notebooks";
+import React from "react";
import Topic from "../components/topic";
import { db } from "../common";
+import ListContainer from "../components/list-container";
+import NotebookNavigator from "../navigation/navigators/nbnavigator";
const Topics = props => {
return (
- <Flex flexDirection="column" flex="1 1 auto">
- <Search placeholder="Search" />
- <List
- style={{
- width: "100%",
- flex: "1 1 auto",
- height: "auto",
- overflowX: "hidden"
- }}
- totalCount={props.topics.length}
- item={index => (
- <Topic
- index={index}
- item={props.topics[index]}
- onClick={() => {
- let topic = props.topics[index];
- NotebookNavigator.navigate("notes", {
- title: topic.title,
- notes: db.getTopic(props.notebookId, topic.title)
- });
- }}
- />
- )}
- />
- <Button Icon={Icon.Plus} content={"Add more topics"} />
- </Flex>
+ <ListContainer
+ itemsLength={props.topics.length}
+ item={index => (
+ <Topic
+ index={index}
+ item={props.topics[index]}
+ onClick={() => {
+ let topic = props.topics[index];
+ NotebookNavigator.navigate("notes", {
+ title: topic.title,
+ notes: db.getTopic(props.notebookId, topic.title)
+ });
+ }}
+ />
+ )}
+ button={{
+ content: "Add more topics"
+ }}
+ />
);
};
diff --git a/apps/web/src/views/Trash.js b/apps/web/src/views/Trash.js
index 09246efbc..4a1433a9a 100644
--- a/apps/web/src/views/Trash.js
+++ b/apps/web/src/views/Trash.js
@@ -51,7 +51,7 @@ function Trash() {
getItems={db.getTrash.bind(db)}
menu={{ menuItems, dropdownRefs }}
button={{
- callToAction: "Clear Trash",
+ content: "Clear Trash",
icon: Icon.Trash2,
onClick: () => db.clearTrash()
}}