Skip to content

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

feat: add notebook navigation

thecodrr44234a07a4cb
diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.js
index e5ed99da6..e54f2fbf7 100644
--- a/apps/web/src/navigation/index.js
+++ b/apps/web/src/navigation/index.js
@@ -1,9 +1,9 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } 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 { Box, Flex, Heading } from "rebass";
import * as Icon from "react-feather";
import theme from "../theme";
@@ -20,12 +20,6 @@ export const routes = {
component: Notebooks,
icon: Icon.Book
},
- lists: {
- key: "lists",
- title: "Lists",
- component: undefined,
- icon: Icon.List
- },
trash: {
key: "trash",
title: "Trash",
@@ -80,11 +74,31 @@ export function goBack(root) {
function ThemedComponent(props) {
const [title, setTitle] = useState(props.route.title);
+ const [canGoBack, setCanGoBack] = useState(false);
+ const [backAction, setBackAction] = useState();
+ useEffect(() => {
+ setTitle(props.route.title);
+ }, [props.route.title]);
return (
<ThemeProvider theme={theme}>
- <Heading fontSize="heading">{title}</Heading>
+ <Flex alignItems="center">
+ <Box
+ onClick={backAction}
+ display={canGoBack ? "flex" : "none"}
+ height={42}
+ color="accent"
+ sx={{ marginLeft: -10 /*correction */ }}
+ >
+ <Icon.ChevronLeft size={42} />
+ </Box>
+ <Heading fontSize="heading">{title}</Heading>
+ </Flex>
{props.route.component && (
- <props.route.component changeTitle={setTitle} />
+ <props.route.component
+ backAction={action => setBackAction(prev => action)}
+ canGoBack={setCanGoBack}
+ changeTitle={setTitle}
+ />
)}
</ThemeProvider>
);
diff --git a/apps/web/src/views/Notebooks.js b/apps/web/src/views/Notebooks.js
index d3102c7ab..19cc89a55 100644
--- a/apps/web/src/views/Notebooks.js
+++ b/apps/web/src/views/Notebooks.js
@@ -12,9 +12,10 @@ import { Virtuoso as List } from "react-virtuoso";
import Notebook from "../components/notebook";
import Topic from "../components/topic";
import Note from "../components/note";
+import { routes } from "../navigation";
const inputRefs = [];
-
+const history = [{}];
const Notebooks = props => {
const [open, setOpen] = useState(false);
const [notebooks, setNotebooks] = useState([]);
@@ -28,6 +29,18 @@ const Notebooks = props => {
Notebooks.onRefresh = undefined;
};
}, []);
+ function navigate(item, save = true, title = undefined) {
+ if (save) {
+ history[history.length] = selected;
+ }
+ props.changeTitle(title || item.title || routes.notebooks.title);
+ props.canGoBack(item.title !== undefined);
+ props.backAction(goBack);
+ setSelected((item.title && item) || {});
+ }
+ function goBack() {
+ navigate(history.pop(), false);
+ }
return (
<Flex flexDirection="column" flex="1 1 auto">
{notebooks.length > 0 ? (
@@ -57,9 +70,7 @@ const Notebooks = props => {
<Topic
index={index}
item={selected.topics[index]}
- onClick={() => {
- setSelected(selected.topics[index]);
- }}
+ onClick={() => navigate(selected.topics[index])}
/>
) : selected.type === "topic" ? (
<Note index={index} item={selected.notes[index]} />
@@ -67,14 +78,10 @@ const Notebooks = props => {
<Notebook
index={index}
item={notebooks[index]}
- onClick={() => {
- props.changeTitle(notebooks[index].title);
- setSelected(notebooks[index]);
- }}
- onTopicClick={(notebook, topic) => {
- props.changeTitle(notebook.title);
- setSelected(topic);
- }}
+ onClick={() => navigate(notebooks[index])}
+ onTopicClick={(notebook, topic) =>
+ navigate(topic, true, notebook.title)
+ }
/>
);
}}