Skip to content

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

fix: a lot of navigation crashes

thecodrr40df62d905e9
diff --git a/apps/web/public/index.html b/apps/web/public/index.html
index 1faa95437..88f014e2f 100644
--- a/apps/web/public/index.html
+++ b/apps/web/public/index.html
@@ -62,7 +62,7 @@
<link
rel="stylesheet"
- href="fonts.css"
+ href="%PUBLIC_URL%/fonts.css"
media="print"
onload="this.media='all'; this.onload=null;"
/>
diff --git a/apps/web/src/components/navigation-menu/index.js b/apps/web/src/components/navigation-menu/index.js
index 9edbacbab..5e5ed2b25 100644
--- a/apps/web/src/components/navigation-menu/index.js
+++ b/apps/web/src/components/navigation-menu/index.js
@@ -15,6 +15,16 @@ import { usePath } from "hookrouter";
import useMobile from "../../utils/use-mobile";
import useTablet from "../../utils/use-tablet";
+function shouldSelectNavItem(route, pin) {
+ if (pin.type === "notebook") {
+ return route === `/notebooks/${pin.id}`;
+ } else if (pin.type === "topic") {
+ return route === `/notebooks/${pin.notebookId}/${pin.id}`;
+ } else if (pin.type === "tag") {
+ return route === `/tags/${pin.id}`;
+ }
+}
+
const routes = [
{ title: "Notes", path: "/", icon: Icon.Note },
{
@@ -161,8 +171,15 @@ function NavigationMenu(props) {
? Icon.Tag2
: Icon.Topic
}
+ selected={shouldSelectNavItem(selectedRoute, pin)}
onClick={() => {
- navigate(``);
+ if (pin.type === "notebook") {
+ navigate(`/notebooks/${pin.id}`);
+ } else if (pin.type === "topic") {
+ navigate(`/notebooks/${pin.notebookId}/${pin.id}`);
+ } else if (pin.type === "tag") {
+ navigate(`/tags/${pin.id}`);
+ }
}}
/>
))}
diff --git a/apps/web/src/components/tag/index.js b/apps/web/src/components/tag/index.js
index 15ad8687c..d18bbc0e9 100644
--- a/apps/web/src/components/tag/index.js
+++ b/apps/web/src/components/tag/index.js
@@ -13,7 +13,7 @@ const menuItems = (item) => [
];
function Tag({ item, index }) {
- const { title, noteIds } = item;
+ const { id, title, noteIds } = item;
return (
<ListItem
item={item}
@@ -23,7 +23,7 @@ function Tag({ item, index }) {
info={`${noteIds.length} notes`}
menuItems={menuItems(item)}
onClick={() => {
- navigate(`/tags/${title}`);
+ navigate(`/tags/${id}`);
}}
/>
);
diff --git a/apps/web/src/views/notebooks.js b/apps/web/src/views/notebooks.js
index 27ef16132..6ab7998d5 100644
--- a/apps/web/src/views/notebooks.js
+++ b/apps/web/src/views/notebooks.js
@@ -13,14 +13,18 @@ const routes = {
"/": () => (
<RouteContainer type="notebooks" title="Notebooks" route={<Notebooks />} />
),
- "/:notebook": ({ notebook }) => (
- <RouteContainer
- type="topics"
- title={db.notebooks.notebook(notebook).title}
- canGoBack
- route={<Topics notebookId={notebook} />}
- />
- ),
+ "/:notebook": ({ notebook }) => {
+ const nbItem = db.notebooks.notebook(notebook);
+ if (!nbItem) return;
+ return (
+ <RouteContainer
+ type="topics"
+ title={nbItem.title}
+ canGoBack
+ route={<Topics notebookId={notebook} />}
+ />
+ );
+ },
"/:notebook/:topic": ({ notebook, topic }) => {
const nb = db.notebooks.notebook(notebook);
const topicItem = nb.topics.topic(topic)._topic;
diff --git a/apps/web/src/views/tags.js b/apps/web/src/views/tags.js
index ddd17965e..6b64d27e9 100644
--- a/apps/web/src/views/tags.js
+++ b/apps/web/src/views/tags.js
@@ -3,19 +3,25 @@ import ListContainer from "../components/list-container";
import { useStore, store } from "../stores/tag-store";
import TagsPlaceholder from "../components/placeholders/tags-placeholder";
import Notes from "./notes";
-import { useRoutes } from "hookrouter";
+import { navigate, useRoutes } from "hookrouter";
import RouteContainer from "../components/route-container";
+import { db } from "../common";
const routes = {
"/": () => <RouteContainer title="Tags" route={<Tags />} />,
- "/:tag": ({ tag }) => (
- <RouteContainer
- type="notes"
- canGoBack
- title={`#${tag}`}
- route={<Notes type="notes" context={{ type: "tag", value: tag }} />}
- />
- ),
+ "/:tag": ({ tag }) => {
+ const tagItem = db.tags.tag(tag);
+ if (!tagItem) return navigate("/");
+ const { title } = tagItem;
+ return (
+ <RouteContainer
+ type="notes"
+ canGoBack
+ title={`#${title}`}
+ route={<Notes type="notes" context={{ type: "tag", value: title }} />}
+ />
+ );
+ },
};
function TagsContainer() {