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: highlight selected route
thecodrr251f9af40afa
diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex 515ab46d8..9f1747bf7 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -77,9 +77,9 @@ const NavMenuItem = props => {};function App() {- const [selectedIndex, setSelectedIndex] = usePersistentState(- "navSelectedIndex",- 0+ const [selectedKey, setSelectedKey] = usePersistentState(+ "navSelectedKey",+ "home");const [show, setShow] = usePersistentState("navContainerState", true);@@ -87,9 +87,8 @@ function App() {const refreshColors = useStore(store => store.refreshColors);const setSelectedContext = useNotesStore(store => store.setSelectedContext);useEffect(() => {- RootNavigator.navigate(Object.keys(RootNavigator.routes)[selectedIndex]);+ RootNavigator.navigate(selectedKey);refreshColors();- console.log(colors);// eslint-disable-next-line react-hooks/exhaustive-deps}, []);const colors = useStore(store => store.colors);@@ -129,24 +128,24 @@ function App() {{Object.values(routes).map((item, index) => (<NavMenuItemonSelected={async () => {- if (selectedIndex === index) {+ if (selectedKey === item.key) {setShow(!show);return;}if (RootNavigator.navigate(item.key)) {- setSelectedIndex(index);+ setSelectedKey(item.key);}}}key={item.key}item={item}- selected={selectedIndex === index}+ selected={selectedKey === item.key}/>))}{colors.map(color => {return (<NavMenuItemonSelected={async () => {- setSelectedIndex(-1);+ setSelectedKey(undefined);setSelectedContext({ type: "color", value: color.title });RootNavigator.navigate("color", {title: toTitleCase(color.title),@@ -172,11 +171,12 @@ function App() {return item.onClick();}if (RootNavigator.navigate(item.key)) {- setSelectedIndex(index);+ setSelectedKey(item.key);}}}key={item.key}item={item}+ selected={selectedKey === item.key}/>))}</Box>diff --git a/apps/web/src/utils/hooks.js b/apps/web/src/utils/hooks.jsindex 7aec1d3f1..a454cc291 100644--- a/apps/web/src/utils/hooks.js+++ b/apps/web/src/utils/hooks.js@@ -1,7 +1,8 @@import { useState } from "react";export const usePersistentState = (key, def) => {- const defState = JSON.parse(window.localStorage.getItem(key) || def);+ let value = window.localStorage.getItem(key) || def;+ const defState = tryParse(value);const [k, setKey] = useState(defState);const _setKey = s => {setKey(s);@@ -9,3 +10,11 @@ export const usePersistentState = (key, def) => {};return [k, _setKey];};++function tryParse(val) {+ try {+ return JSON.parse(val);+ } catch (e) {+ return val;+ }+}