Skip to content

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

feat: migrate to raviger from hookrouter

thecodrread437ab344e
diff --git a/apps/web/package.json b/apps/web/package.json
index 6b1083310..24d292fed 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -14,7 +14,6 @@
"eventsource": "^1.0.7",
"fast-sort": "^2.1.1",
"framer-motion": "^2.6.15",
- "hookrouter": "^1.2.3",
"immer": "^6.0.3",
"localforage": "^1.7.3",
"localforage-getitems": "https://github.com/thecodrr/localForage-getItems.git",
@@ -22,6 +21,7 @@
"qclone": "^1.0.4",
"quill": "https://github.com/thecodrr/quill.git#1.3.7",
"quill-magic-url": "^1.0.3",
+ "raviger": "^2.0.0",
"react": "^16.13.1",
"react-app-polyfill": "^1.0.6",
"react-dom": "^16.13.1",
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index a5675baaa..11b8aa01f 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -8,7 +8,7 @@ import { useStore as useUserStore } from "./stores/user-store";
import { useStore as useNotesStore } from "./stores/note-store";
import Animated from "./components/animated";
import NavigationMenu from "./components/navigationmenu";
-import { useRoutes } from "hookrouter";
+import { useRoutes } from "raviger";
import routes from "./navigation/routes";
import Editor from "./components/editor";
import useMobile from "./utils/use-mobile";
diff --git a/apps/web/src/common/list-profiles.js b/apps/web/src/common/list-profiles.js
index f3c7804de..63e89a230 100644
--- a/apps/web/src/common/list-profiles.js
+++ b/apps/web/src/common/list-profiles.js
@@ -1,4 +1,4 @@
-import { navigate } from "hookrouter";
+import { navigate } from "raviger";
import React from "react";
import Note from "../components/note";
import Notebook from "../components/notebook";
diff --git a/apps/web/src/components/navigation-menu/index.js b/apps/web/src/components/navigation-menu/index.js
index 46ecf98d6..5bbecc684 100644
--- a/apps/web/src/components/navigation-menu/index.js
+++ b/apps/web/src/components/navigation-menu/index.js
@@ -7,11 +7,11 @@ import { useStore as useUserStore } from "../../stores/user-store";
import { useStore as useThemeStore } from "../../stores/theme-store";
import Animated from "../animated";
import NavigationItem from "./navigation-item";
-import { navigate } from "hookrouter";
+import { navigate } from "raviger";
import { toTitleCase } from "../../utils/string";
import { COLORS } from "../../common";
import { showLogInDialog } from "../dialogs/logindialog";
-import { usePath } from "hookrouter";
+import { usePath } from "raviger";
import useMobile from "../../utils/use-mobile";
import useTablet from "../../utils/use-tablet";
diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.js
index 756072d7b..54088a0dd 100644
--- a/apps/web/src/components/properties/index.js
+++ b/apps/web/src/components/properties/index.js
@@ -10,7 +10,7 @@ import Animated from "../animated";
import Toggle from "./toggle";
import { toTitleCase } from "../../utils/string";
import { showMoveNoteDialog } from "../dialogs/movenotedialog";
-import { navigate } from "hookrouter";
+import { navigate } from "raviger";
const tools = [
{ key: "pinned", icons: { on: Icon.PinFilled, off: Icon.Pin }, label: "Pin" },
diff --git a/apps/web/src/components/route-container/index.js b/apps/web/src/components/route-container/index.js
index c6c57bc6c..2e1b9de8e 100644
--- a/apps/web/src/components/route-container/index.js
+++ b/apps/web/src/components/route-container/index.js
@@ -1,25 +1,16 @@
import React from "react";
-import Animated from "../animated";
import { Box, Flex, Text } from "rebass";
import * as Icon from "../icons";
import { useStore } from "../../stores/app-store";
import { useStore as useSelectionStore } from "../../stores/selection-store";
import { CREATE_BUTTON_MAP, SELECTION_OPTIONS_MAP } from "../../common";
import useMobile from "../../utils/use-mobile";
-import { navigate } from "hookrouter";
+import { navigate } from "raviger";
function RouteContainer(props) {
const { type, route, canGoBack, title, subtitle, onlyBackButton } = props;
return (
- <Animated.Flex
- sx={{ overflow: "hidden" }}
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- transition={{ duration: 0.3, ease: "easeIn" }}
- exit={{ opacity: 0 }}
- flexDirection="column"
- flex="1 1 auto"
- >
+ <>
<Header
type={type}
canGoBack={canGoBack}
@@ -28,7 +19,7 @@ function RouteContainer(props) {
onlyBackButton={onlyBackButton}
/>
{route}
- </Animated.Flex>
+ </>
);
}
diff --git a/apps/web/src/components/tag/index.js b/apps/web/src/components/tag/index.js
index d18bbc0e9..378adff16 100644
--- a/apps/web/src/components/tag/index.js
+++ b/apps/web/src/components/tag/index.js
@@ -1,6 +1,6 @@
import React from "react";
import ListItem from "../list-item";
-import { navigate } from "hookrouter";
+import { navigate } from "raviger";
import { Text } from "rebass";
import { store as appStore } from "../../stores/app-store";
import { db } from "../../common";
diff --git a/apps/web/src/navigation/routes.js b/apps/web/src/navigation/routes.js
index d696088d1..83e024208 100644
--- a/apps/web/src/navigation/routes.js
+++ b/apps/web/src/navigation/routes.js
@@ -9,11 +9,49 @@ import Notes from "../views/notes.js";
import Search from "../views/search";
import Settings from "../views/settings";
import Tags from "../views/tags";
+import Topics from "../views/topics";
+import { navigate } from "raviger";
import Trash from "../views/trash";
const routes = {
"/": () => <RouteContainer type="notes" title="Notes" route={<Home />} />,
- "/notebooks*": () => <Notebooks />,
+ "/notebooks": () => (
+ <RouteContainer type="notebooks" title="Notebooks" route={<Notebooks />} />
+ ),
+ "/notebooks/:notebook": ({ notebook }) => {
+ const nbItem = db.notebooks.notebook(notebook);
+ if (!nbItem) return;
+ return (
+ <RouteContainer
+ type="topics"
+ title={nbItem.title}
+ canGoBack
+ route={<Topics notebookId={notebook} />}
+ />
+ );
+ },
+ "/notebooks/:notebook/:topic": ({ notebook, topic }) => {
+ const nb = db.notebooks.notebook(notebook);
+ const topicItem = nb.topics.topic(topic)._topic;
+ if (!topicItem) return navigate(`/notebooks/${nb.id}`);
+
+ return (
+ <RouteContainer
+ type="notes"
+ title={nb.title}
+ canGoBack
+ subtitle={topicItem.title}
+ route={
+ <Notes
+ context={{
+ type: "topic",
+ value: { id: notebook, topic: topic },
+ }}
+ />
+ }
+ />
+ );
+ },
"/favorites": () => (
<RouteContainer
title="Favorites"
@@ -29,7 +67,22 @@ const routes = {
"/trash": () => (
<RouteContainer type="trash" title="Trash" route={<Trash />} />
),
- "/tags*": () => <Tags />,
+ "/tags": () => <RouteContainer title="Tags" route={<Tags />} />,
+ "/tags/: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: tagItem.id }} />
+ }
+ />
+ );
+ },
"/colors/:color": ({ color }) => (
<RouteContainer
type="notes"
diff --git a/apps/web/src/views/notebooks.js b/apps/web/src/views/notebooks.js
index 6ab7998d5..b94b92822 100644
--- a/apps/web/src/views/notebooks.js
+++ b/apps/web/src/views/notebooks.js
@@ -3,56 +3,6 @@ import { showAddNotebookDialog } 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 Topics from "./topics.js";
-import Notes from "./notes.js";
-import { useRoutes, navigate } from "hookrouter";
-import RouteContainer from "../components/route-container";
-import { db } from "../common";
-
-const routes = {
- "/": () => (
- <RouteContainer type="notebooks" title="Notebooks" route={<Notebooks />} />
- ),
- "/: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;
- if (!topicItem) return navigate(`/notebooks/${nb.id}`);
-
- return (
- <RouteContainer
- type="notes"
- title={nb.title}
- canGoBack
- subtitle={topicItem.title}
- route={
- <Notes
- context={{
- type: "topic",
- value: { id: notebook, topic: topic },
- }}
- />
- }
- />
- );
- },
-};
-
-function NotebooksContainer() {
- const routeResult = useRoutes(routes);
- return routeResult;
-}
function Notebooks() {
useEffect(() => store.refresh(), []);
@@ -73,4 +23,4 @@ function Notebooks() {
);
}
-export default NotebooksContainer;
+export default Notebooks;
diff --git a/apps/web/src/views/search.js b/apps/web/src/views/search.js
index 8c9346f4d..743a784cc 100644
--- a/apps/web/src/views/search.js
+++ b/apps/web/src/views/search.js
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import ListContainer from "../components/list-container";
import SearchPlaceholder from "../components/placeholders/search-placeholder";
-import { useQueryParams } from "hookrouter";
+import { useQueryParams } from "raviger";
import { db, notesFromContext } from "../common";
import SearchBox from "../components/search";
import ProgressBar from "../components/progress-bar";
@@ -34,8 +34,7 @@ function Search() {
totalItems: 0,
});
const [results, setResults] = useState([]);
- const [params] = useQueryParams();
- const { type } = params;
+ const [{ type }] = useQueryParams();
const context = useNoteStore((store) => store.context);
return (
diff --git a/apps/web/src/views/tags.js b/apps/web/src/views/tags.js
index f45c192cb..9b19cdf31 100644
--- a/apps/web/src/views/tags.js
+++ b/apps/web/src/views/tags.js
@@ -2,34 +2,6 @@ import React, { useEffect } from "react";
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 { navigate, useRoutes } from "hookrouter";
-import RouteContainer from "../components/route-container";
-import { db } from "../common";
-
-const routes = {
- "/": () => <RouteContainer title="Tags" route={<Tags />} />,
- "/: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: tagItem.id }} />
- }
- />
- );
- },
-};
-
-function TagsContainer() {
- const routeResult = useRoutes(routes);
- return routeResult;
-}
function Tags() {
const tags = useStore((store) => store.tags);
@@ -42,4 +14,4 @@ function Tags() {
);
}
-export default TagsContainer;
+export default Tags;
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index ed2ccaf0b..3e2d1adff 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -6263,11 +6263,6 @@ homedir-polyfill@^1.0.0:
dependencies:
parse-passwd "^1.0.0"
-hookrouter@^1.2.3:
- version "1.2.3"
- resolved "https://registry.yarnpkg.com/hookrouter/-/hookrouter-1.2.3.tgz#a65599a1be376b51734caf7c4f7f8aba59bb2c77"
- integrity sha512-n0mqEBGgXIxYRNMHlwCzoyTOk0OB5Es3jwUyA3+2l5nte/52n0CMMj1bmoCabC8K43YTUEr0zzexTBfo//tq2Q==
-
hoopy@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/hoopy/-/hoopy-0.1.4.tgz#609207d661100033a9a9402ad3dea677381c1b1d"
@@ -10692,6 +10687,11 @@ range-parser@^1.2.1, range-parser@~1.2.1:
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"
integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==
+raviger@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/raviger/-/raviger-2.0.0.tgz#f7a2db58dc86b89ba191806f64c86ac6154d3641"
+ integrity sha512-LdjNxTs8wtGFrK0tuyX+shkMa0VEk7L1qyjmquoMmRXEEgJXgWpZ5MoiPIsuGs5eQZOrAh22Y5h1+pzoLRgLUg==
+
version "2.4.0"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.4.0.tgz#a1ce6fb9c9bc356ca52e89256ab59059e13d0332"