A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: direct navigation to routes not possible
thecodrr02d0694736bc
diff --git a/apps/web/package.json b/apps/web/package.jsonindex bb099326e..7345bc91b 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -21,7 +21,6 @@"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",@@ -34,6 +33,7 @@"rebass": "^4.0.7","timeago-react": "^3.0.0","uzip": "^0.20201126.0",+ "wouter": "^2.7.0","zustand": "^2.2.3"},"devDependencies": {diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex 265bac35c..82ebfe4a0 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -8,7 +8,6 @@ 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 "raviger";import routes from "./navigation/routes";import Editor from "./components/editor";import useMobile from "./utils/use-mobile";@@ -24,6 +23,7 @@ import {showPasswordChangedNotice,} from "./components/dialogs/confirm";import StatusBar from "./components/statusbar";+import useRoutes from "./utils/useRouter";function App() {const [show, setShow] = useState(true);diff --git a/apps/web/src/common/list-profiles.js b/apps/web/src/common/list-profiles.jsindex 63e89a230..920a268f5 100644--- a/apps/web/src/common/list-profiles.js+++ b/apps/web/src/common/list-profiles.js@@ -1,4 +1,4 @@-import { navigate } from "raviger";+import { navigate } from "../navigation/";import React from "react";import Note from "../components/note";import Notebook from "../components/notebook";diff --git a/apps/web/src/components/dialogs/dialog.js b/apps/web/src/components/dialogs/dialog.jsindex 45cf410cd..ea10e93bf 100644--- a/apps/web/src/components/dialogs/dialog.js+++ b/apps/web/src/components/dialogs/dialog.js@@ -146,17 +146,22 @@ export function showDialog(dialog) {const perform = (result) => {window.removeEventListener("hashchange", onHashChange);ReactDOM.unmountComponentAtNode(root);+ setHashParam(undefined, false, false, false);resolve(result);};window.addEventListener("hashchange", onHashChange);function onHashChange() {- if (!getHashParam("type")) perform(false);+ if (!getHashParam("dialog")) perform(false);}- setHashParam({ type: "dialog" }, true, true, true);-const PropDialog = dialog(perform);+ setHashParam(+ { dialog: PropDialog.type.name.toLowerCase() },+ true,+ true,+ true+ );ReactDOM.render(<ThemeProvider>{PropDialog}</ThemeProvider>, root);});}diff --git a/apps/web/src/components/navigation-menu/index.js b/apps/web/src/components/navigation-menu/index.jsindex 5bbecc684..56ef7f07a 100644--- a/apps/web/src/components/navigation-menu/index.js+++ b/apps/web/src/components/navigation-menu/index.js@@ -1,4 +1,4 @@-import React, { useEffect, useState } from "react";+import React from "react";import ReactDOM from "react-dom";import { Flex } from "rebass";import { useStore as useAppStore } from "../../stores/app-store";@@ -7,13 +7,13 @@ 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 "raviger";+import { navigate } from "../../navigation";import { toTitleCase } from "../../utils/string";import { COLORS } from "../../common";import { showLogInDialog } from "../dialogs/logindialog";-import { usePath } from "raviger";import useMobile from "../../utils/use-mobile";import useTablet from "../../utils/use-tablet";+import { useLocation } from "wouter";function shouldSelectNavItem(route, pin) {if (pin.type === "notebook") {@@ -51,8 +51,7 @@ const bottomRoutes = [function NavigationMenu(props) {const { toggleNavigationContainer } = props;- const path = usePath(false);- const [selectedRoute, setSelectedRoute] = useState(path);+ const [location] = useLocation();const isFocusMode = useAppStore((store) => store.isFocusMode);const colors = useAppStore((store) => store.colors);const pins = useAppStore((store) => store.menuPins);@@ -67,10 +66,6 @@ function NavigationMenu(props) {const isMobile = useMobile();const isTablet = useTablet();- useEffect(() => {- setSelectedRoute(path);- }, [path]);-return (<Animated.Flexid="navigationmenu"@@ -129,12 +124,11 @@ function NavigationMenu(props) {icon={item.icon}selected={item.path === "/"- ? selectedRoute === item.path- : selectedRoute.startsWith(item.path)+ ? location === item.path+ : location.startsWith(item.path)}onClick={() => {- setSelectedRoute(item.path);- if (!isMobile && !isTablet && selectedRoute === item.path)+ if (!isMobile && !isTablet && location === item.path)return toggleNavigationContainer();toggleNavigationContainer(true);navigate(item.path);@@ -146,7 +140,7 @@ function NavigationMenu(props) {key={color.title}title={toTitleCase(color.title)}icon={Icon.Circle}- selected={selectedRoute === `/colors/${color.id}`}+ selected={location === `/colors/${color.id}`}color={COLORS[color.title]}onClick={() => {navigate(`/colors/${color.id}`);@@ -172,7 +166,7 @@ function NavigationMenu(props) {? Icon.Tag2: Icon.Topic}- selected={shouldSelectNavItem(selectedRoute, pin)}+ selected={shouldSelectNavItem(location, pin)}onClick={() => {if (pin.type === "notebook") {navigate(`/notebooks/${pin.id}`);@@ -223,9 +217,8 @@ function NavigationMenu(props) {icon={item.icon}onClick={() => {navigate(item.path);- setSelectedRoute(item.path);}}- selected={selectedRoute.startsWith(item.path)}+ selected={location.startsWith(item.path)}/>))}</Flex>diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.jsindex a68682685..9f2de9191 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 "raviger";+import { navigate } from "../../navigation";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.jsindex 2e1b9de8e..9822bfdae 100644--- a/apps/web/src/components/route-container/index.js+++ b/apps/web/src/components/route-container/index.js@@ -5,7 +5,7 @@ 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 "raviger";+import { navigate } from "../../navigation";function RouteContainer(props) {const { type, route, canGoBack, title, subtitle, onlyBackButton } = props;diff --git a/apps/web/src/components/status-bar/index.js b/apps/web/src/components/status-bar/index.jsindex b2ade3bc1..a6cea3621 100644--- a/apps/web/src/components/status-bar/index.js+++ b/apps/web/src/components/status-bar/index.js@@ -5,7 +5,7 @@ import * as Icon from "../icons";import { useStore as useUserStore } from "../../stores/user-store";import { showLogInDialog } from "../dialogs/logindialog";import TimeAgo from "timeago-react";-import { navigate } from "raviger";+import { navigate } from "../../navigation";function StatusBar() {const user = useUserStore((state) => state.user);diff --git a/apps/web/src/components/tag/index.js b/apps/web/src/components/tag/index.jsindex 378adff16..e5bba6681 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 "raviger";+import { navigate } from "../../navigation";import { Text } from "rebass";import { store as appStore } from "../../stores/app-store";import { db } from "../../common";diff --git a/apps/web/src/index.js b/apps/web/src/index.jsindex 0f6f5dda9..2dc8d34a2 100644--- a/apps/web/src/index.js+++ b/apps/web/src/index.js@@ -9,7 +9,7 @@ import "./index.css";import * as serviceWorker from "./serviceWorker";import Modal from "react-modal";import rootroutes from "./navigation/rootRoutes";-import { useRoutes } from "raviger";+import useRoutes from "./utils/useRouter";// Sentry.init({// dsn:diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.jsnew file mode 100644index 000000000..b52c80f2f--- /dev/null+++ b/apps/web/src/navigation/index.js@@ -0,0 +1,70 @@+import { useState } from "react";+// import { useCallback } from "react";++export function navigate(url, replaceOrQuery, replace) {+ if (typeof url !== "string") {+ throw new Error(`"url" must be a string, was provided a(n) ${typeof url}`);+ }+ if (Array.isArray(replaceOrQuery)) {+ throw new Error(+ '"replaceOrQuery" must be boolean, object, or URLSearchParams'+ );+ }++ if (replaceOrQuery !== null && typeof replaceOrQuery === "object") {+ url += "?" + new URLSearchParams(replaceOrQuery).toString();+ } else if (replace === undefined && replaceOrQuery !== undefined) {+ replace = replaceOrQuery;+ } else if (replace === undefined && replaceOrQuery === undefined) {+ replace = false;+ }++ window.history[`${replace ? "replace" : "push"}State`](null, null, url);+ dispatchEvent(new PopStateEvent("popstate", null));+}++export function useQueryParams(+ parseFn = parseQuery+ //serializeFn = serializeQuery+) {+ const [querystring] = useState(getQueryString());+ // const setQueryParams = useCallback(+ // (params, { replace = true } = {}) => {+ // let path = getCurrentPath();+ // params = replace ? params : { ...parseFn(querystring), ...params };+ // const serialized = serializeFn(params).toString();+ // if (serialized) path += "?" + serialized;+ // if (!replace) path += getCurrentHash();+ // navigate(path);+ // },+ // [querystring]+ // );+ // Update state when route changes+ // const updateQuery = useCallback(() => setQuerystring(getQueryString()), [+ // setQueryParams,+ // ]);+ //useLocationChange(updateQuery);+ return [parseFn(querystring)];+}++function parseQuery(querystring) {+ return Object.fromEntries(new URLSearchParams(querystring).entries());+}++// function serializeQuery(queryParams) {+// return new URLSearchParams(+// Object.entries(queryParams).filter(([, v]) => v !== null)+// );+// }++export function getQueryString() {+ return window.location.search;+}++export function getCurrentPath() {+ return window.location.pathname || "/";+}++export function getCurrentHash() {+ return window.location.hash;+}diff --git a/apps/web/src/navigation/routes.js b/apps/web/src/navigation/routes.jsindex 83e024208..a4a57007c 100644--- a/apps/web/src/navigation/routes.js+++ b/apps/web/src/navigation/routes.js@@ -10,7 +10,7 @@ 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 { navigate } from "../navigation";import Trash from "../views/trash";const routes = {diff --git a/apps/web/src/utils/useRouter.js b/apps/web/src/utils/useRouter.jsnew file mode 100644index 000000000..92510c853--- /dev/null+++ b/apps/web/src/utils/useRouter.js@@ -0,0 +1,18 @@+import React from "react";+import { useRouter } from "wouter";++export default function useRoutes(routes, options) {+ const router = useRouter();+ const [location] = router.hook();+ const matcher = router.matcher;++ for (var key in routes) {+ const [match, params] = matcher(key, location);+ if (match) {+ return routes[key](params);+ }+ }+ if (!options) return;+ const { fallbackRoute } = options;+ if (fallbackRoute && routes[fallbackRoute]) return routes[fallbackRoute]();+}diff --git a/apps/web/src/views/recovery.js b/apps/web/src/views/recovery.jsindex d8aab16fb..fb05ed707 100644--- a/apps/web/src/views/recovery.js+++ b/apps/web/src/views/recovery.js@@ -1,6 +1,6 @@import React, { useEffect, useState } from "react";import { Button, Flex, Text } from "rebass";-import { navigate, useQueryParams } from "raviger";+import { navigate, useQueryParams } from "../navigation";import ThemeProvider from "../components/theme-provider";import Field from "../components/field";import * as Icon from "../components/icons";diff --git a/apps/web/src/views/search.js b/apps/web/src/views/search.jsindex 743a784cc..1fa6889bc 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 "raviger";+import { useQueryParams } from "../navigation";import { db, notesFromContext } from "../common";import SearchBox from "../components/search";import ProgressBar from "../components/progress-bar";diff --git a/apps/web/yarn.lock b/apps/web/yarn.lockindex c8eb194b9..6117832e2 100644--- a/apps/web/yarn.lock+++ b/apps/web/yarn.lock@@ -10703,11 +10703,6 @@ 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"@@ -13308,6 +13303,11 @@ worker-rpc@^0.1.0:dependencies:microevent.ts "~0.1.1"+wouter@^2.7.0:+ version "2.7.0"+ resolved "https://registry.yarnpkg.com/wouter/-/wouter-2.7.0.tgz#53ad898bea11ac497d0aab8e0173748962f8709a"+ integrity sha512-+0KbaxtM8pcLZWH22oaatq1Rbtce+0KXnrGCjy/GSFPNs3pTyyL6nQoiPga+96LqO8SPnC8wy15jD7Ix/tZm1A==+wrap-ansi@^2.0.0:version "2.1.0"resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"