Skip to content

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

ui(properties): show the notebook a note is in

thecodrr3fe1a0b9d8ef
diff --git a/apps/web/package.json b/apps/web/package.json
index 9f1bbdb53..516a48255 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -14,6 +14,7 @@
"localforage": "^1.7.3",
"localforage-getitems": "https://github.com/thecodrr/localForage-getItems.git",
"notes-core": "npm:@streetwriters/notesnook-core@latest",
+ "qclone": "^1.0.4",
"quill": "https://github.com/thecodrr/quill.git#1.3.7",
"quill-magic-url": "^1.0.3",
"react": "^16.13.1",
diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.js
index 7ab46b550..f20677428 100644
--- a/apps/web/src/components/properties/index.js
+++ b/apps/web/src/components/properties/index.js
@@ -1,15 +1,16 @@
-import React, { useCallback } from "react";
+import React, { useCallback, useEffect, useState } from "react";
import * as Icon from "../icons";
import { Flex, Text, Button } from "rebass";
import { Input } from "@rebass/forms";
import { useStore } from "../../stores/editor-store";
-import { COLORS } from "../../common";
+import { COLORS, db } from "../../common";
import { objectMap } from "../../utils/object";
import { useStore as useAppStore } from "../../stores/app-store";
import Animated from "../animated";
import Toggle from "./toggle";
import { toTitleCase } from "../../utils/string";
import { showMoveNoteDialog } from "../dialogs/movenotedialog";
+import RootNavigator from "../../navigation/navigators/rootnavigator";
const tools = [
{ key: "pinned", icons: { on: Icon.PinFilled, off: Icon.Pin }, label: "Pin" },
@@ -22,10 +23,12 @@ const tools = [
];
function Properties() {
+ const [notebook, setNotebook] = useState();
const colors = useStore((store) => store.session.colors);
const toggleLocked = useStore((store) => store.toggleLocked);
const tags = useStore((store) => store.session.tags);
const sessionId = useStore((store) => store.session.id);
+ const notebookData = useStore((store) => store.session.notebook);
const setSession = useStore((store) => store.setSession);
const setColor = useStore((store) => store.setColor);
const setTag = useStore((store) => store.setTag);
@@ -46,6 +49,12 @@ function Properties() {
[setSession, toggleLocked]
);
+ useEffect(() => {
+ if (notebookData && notebookData.id) {
+ setNotebook(db.notebooks.notebook(notebookData.id).data);
+ }
+ }, [notebookData]);
+
return (
!isFocusMode && (
<>
@@ -114,8 +123,42 @@ function Properties() {
await showMoveNoteDialog([sessionId]);
}}
>
- Add to notebook
+ {notebook ? "Move to another notebook" : "Add to notebook"}
</Button>
+ {notebook && (
+ <Text as="span" variant="subBody" mt={1}>
+ In{" "}
+ <Text
+ as="span"
+ color="primary"
+ sx={{ cursor: "pointer" }}
+ onClick={() => {
+ RootNavigator.navigate(
+ "notebooks",
+ { params: { id: notebookData.id } },
+ true
+ );
+ }}
+ >
+ {notebook.title}
+ </Text>{" "}
+ under{" "}
+ <Text
+ as="span"
+ color="primary"
+ sx={{ cursor: "pointer" }}
+ onClick={() => {
+ RootNavigator.navigate(
+ "notebooks",
+ { params: notebookData },
+ true
+ );
+ }}
+ >
+ {notebookData.topic}
+ </Text>
+ </Text>
+ )}
<Flex flexDirection="column">
{objectMap(COLORS, (label, code) => (
<Flex
@@ -177,6 +220,7 @@ function Properties() {
marginRight: 1,
cursor: "pointer",
}}
+ fontSize={"subBody"}
onClick={() => {
setTag(tag);
}}
diff --git a/apps/web/src/navigation/container.js b/apps/web/src/navigation/container.js
index ccbda363d..474d9553e 100644
--- a/apps/web/src/navigation/container.js
+++ b/apps/web/src/navigation/container.js
@@ -3,8 +3,8 @@ import { Flex } from "rebass";
function NavigationContainer(props) {
useEffect(() => {
- props.navigator.onLoad();
- }, [props.navigator]);
+ props.navigator.onLoad(props.params);
+ }, [props.params, props.navigator]);
return <Flex className={props.navigator.root} variant="columnFill" />;
}
export default NavigationContainer;
diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.js
index de8a28891..1af49ddf5 100644
--- a/apps/web/src/navigation/index.js
+++ b/apps/web/src/navigation/index.js
@@ -7,6 +7,7 @@ import { store as appStore } from "../stores/app-store";
import Route from "./route";
import Config from "../utils/config";
import { isMobile } from "../utils/dimensions";
+import { qclone } from "qclone";
class Navigator {
constructor(root, routes, options = {}) {
@@ -18,7 +19,7 @@ class Navigator {
this.onNavigate = () => {};
}
- onLoad = () => {
+ onLoad = (params = null) => {
if (!this.options.persist) return;
const opts = Config.get(this.root, {
@@ -27,18 +28,26 @@ class Navigator {
});
this.history = opts.history;
this.lastRoute = undefined;
- this.navigate(opts.lastRoute.key, opts.lastRoute.params, true);
+ this.navigate(
+ opts.lastRoute.key,
+ { ...opts.lastRoute.params, ...params, noPersist: true },
+ true
+ );
};
getRoute(key) {
- return this.routes[key];
+ return qclone(this.routes[key]);
}
pushToHistory() {
const lastItem = this.history[this.history.length - 1];
if (this.lastRoute) {
if (lastItem && lastItem.key === this.lastRoute.key) return;
- this.history.push(this.lastRoute);
+ const route = qclone(this.lastRoute);
+ if (route.params && route.params.noPersist) {
+ route.params = {};
+ }
+ this.history.push(route);
}
}
@@ -46,9 +55,10 @@ class Navigator {
if (!this.options.persist) return;
this.lastRoute = route;
+
// cache the route in localStorage
// NOTE: we delete the navigator key if any so it's always new across refreshes
- const copy = { ...route, params: { ...route.params } };
+ const copy = qclone(route);
if (copy.params.navigator) delete copy.params.navigator;
Config.set(this.root, {
history: this.history,
@@ -63,12 +73,12 @@ class Navigator {
getNavigationRoute(routeName, params = {}, force = false) {
let route = this.getRoute(routeName);
- this.onNavigate(route);
-
if (!force && (!route || this.lastRoute === route)) {
return false;
}
+ this.onNavigate(route);
+
route.params = { ...route.params, ...params };
this.pushToHistory();
diff --git a/apps/web/src/views/Notebooks.js b/apps/web/src/views/Notebooks.js
index 3e55657a7..cf2dd881b 100644
--- a/apps/web/src/views/Notebooks.js
+++ b/apps/web/src/views/Notebooks.js
@@ -4,12 +4,36 @@ import AddNotebookDialog from "../components/dialogs/addnotebookdialog";
import ListContainer from "../components/list-container";
import { useStore, store } from "../stores/notebook-store";
import NotebooksPlaceholder from "../components/placeholders/notebooks-placeholder";
+import { db } from "../common";
function Notebooks(props) {
const [open, setOpen] = useState(false);
useEffect(() => store.refresh(), []);
const notebooks = useStore((state) => state.notebooks);
const add = useStore((state) => state.add);
+
+ useEffect(() => {
+ if (props.id) {
+ const notebook = db.notebooks.notebook(props.id);
+ if (props.topic) {
+ props.navigator.navigate("notes", {
+ title: notebook.title,
+ subtitle: props.topic,
+ context: {
+ type: "topic",
+ value: { id: props.id, topic: props.topic },
+ },
+ });
+ } else {
+ props.navigator.navigate("topics", {
+ title: notebook.title,
+ topics: notebook.data.topics,
+ notebook: notebook.data,
+ });
+ }
+ }
+ }, [props.id, props.topic, props.navigator]);
+
return (
<>
<ListContainer