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
refactor: seperate navigationmenu from app.js
thecodrr5a4f923e9a6e
diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex b8fd578c0..0a1609a56 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -1,43 +1,25 @@import React, { useEffect } from "react";import "./app.css";import Editor from "./components/editor";-import { motion } from "framer-motion";import { Flex, Box } from "rebass";import ThemeProvider from "./components/theme-provider";-import RootNavigator, {- bottomRoutes,- routes-} from "./navigation/navigators/rootnavigator";import { usePersistentState } from "./utils/hooks";import { useStore } from "./stores/app-store";-import { useStore as useNotesStore } from "./stores/note-store";-import { COLORS } from "./common";-import { toTitleCase } from "./utils/string";-import * as Icon from "./components/icons";import { useStore as useAppStore } from "./stores/app-store";import { useStore as useUserStore } from "./stores/user-store";import Animated from "./components/animated";-import NavItem from "./components/navitem";+import NavigationMenu from "./components/navigationmenu";function App() {- const [selectedKey, setSelectedKey] = usePersistentState(- "navSelectedKey",- "home"- );- const [show, setShow] = usePersistentState("navContainerState", true);-- const isSideMenuOpen = useStore(store => store.isSideMenuOpen);+ const [show, setShow] = usePersistentState("isContainerVisible", true);const refreshColors = useStore(store => store.refreshColors);- const setSelectedContext = useNotesStore(store => store.setSelectedContext);const isFocusModeEnabled = useAppStore(store => store.isFocusModeEnabled);const initUser = useUserStore(store => store.init);useEffect(() => {- RootNavigator.navigate(selectedKey);refreshColors();initUser();- // eslint-disable-next-line react-hooks/exhaustive-deps- }, []);+ }, [refreshColors, initUser]);useEffect(() => {if (isFocusModeEnabled) {@@ -48,114 +30,13 @@ function App() {// eslint-disable-next-line react-hooks/exhaustive-deps}, [isFocusModeEnabled]);- const colors = useStore(store => store.colors);return (<ThemeProvider>- <Flex- bg="background"- sx={{ color: "text" }}- height="100%"- alignContent="stretch"- >- <Animated.Flex- flexDirection="column"- justifyContent="space-between"- initial={{ opacity: 1 }}- animate={{ opacity: isFocusModeEnabled ? 0 : 1 }}- transition={{ duration: 0.3, ease: "easeOut" }}- sx={{- zIndex: 999,- borderRight: "1px solid",- borderRightColor: "primary",- minWidth: ["85%", 50, 50],- maxWidth: ["85%", 50, 50],- display: [isSideMenuOpen ? "flex" : "none", "flex", "flex"],- position: ["absolute", "relative", "relative"]- }}- bg={"background"}- px={0}- >- <Box- sx={{- overflow: "scroll",- scrollbarWidth: "none",- //TODO: need to test this on webkit and internet explorer- "::-webkit-scrollbar": { width: 0, height: 0 },- msOverflowStyle: "none"- //"-ms-overflow-style": "none"- }}- >- {Object.values(routes).map((item, index) => (- <NavItem- onSelected={async () => {- if (selectedKey === item.key) {- setShow(!show);- return;- }- if (item.onClick) {- setSelectedKey(item.key);- return item.onClick();- }- if (RootNavigator.navigate(item.key)) {- setSelectedKey(item.key);- }- }}- key={item.key}- item={item}- selected={selectedKey === item.key}- />- ))}- {colors.map(color => {- return (- <NavItem- onSelected={async () => {- setSelectedKey(undefined);- setSelectedContext({- type: "color",- value: color.title- });- RootNavigator.navigate(- "color",- {- title: toTitleCase(color.title),- context: { colors: [color.title] }- },- true- );- }}- key={color.title}- item={{- color: COLORS[color.title],- title: toTitleCase(color.title),- icon: Icon.Circle,- count: color.noteIds.length- }}- />- );- })}- </Box>- <Box>- {Object.values(bottomRoutes).map((item, index) => (- <NavItem- onSelected={async () => {- if (item.onClick) {- await item.onClick();- if (item.component) setSelectedKey(item.key);- return;- }- if (RootNavigator.navigate(item.key)) {- setSelectedKey(item.key);- }- }}- key={item.key}- item={item}- selected={selectedKey === item.key}- />- ))}- </Box>- </Animated.Flex>- <Flex flex="1 1 auto" flexDirection="row" alignContent="stretch" px={0}>- <motion.div+ <Flex bg="background" height="100%">+ <NavigationMenu toggleNavigationContainer={() => setShow(!show)} />+ <Flex flex="1 1 auto">+ <Animated.Flex+ className="RootNavigator"initial={{ width: "30%", opacity: 1, scaleY: 1 }}animate={{width: show ? "30%" : "0%",@@ -164,21 +45,13 @@ function App() {zIndex: show ? 0 : -1}}transition={{ duration: 0.3, ease: "easeOut" }}- style={{- display: "flex",- flex: "1 1 auto"+ flex="1 1 auto"+ flexDirection="column"+ sx={{+ borderRight: "1px solid",+ borderColor: "border"}}- >- <Flex- className="RootNavigator"- flex="1 1 auto"- flexDirection="column"- sx={{- borderRight: "1px solid",- borderColor: "border"- }}- />- </motion.div>+ /><Editor /></Flex><Box id="dialogContainer" />diff --git a/apps/web/src/components/navigation-menu/index.js b/apps/web/src/components/navigation-menu/index.jsnew file mode 100644index 000000000..9057bf8b0--- /dev/null+++ b/apps/web/src/components/navigation-menu/index.js@@ -0,0 +1,109 @@+import React, { useEffect } from "react";+import { Box } from "rebass";+import RootNavigator, {+ bottomRoutes,+ routes+} from "../../navigation/navigators/rootnavigator";+import { usePersistentState } from "../../utils/hooks";+import { useStore } from "../../stores/app-store";+import { COLORS } from "../../common";+import { toTitleCase } from "../../utils/string";+import * as Icon from "../icons";+import { useStore as useAppStore } from "../../stores/app-store";+import Animated from "../animated";+import NavItem from "../navitem";+import { objectMap } from "../../utils/object";++function NavigationMenu(props) {+ const { toggleNavigationContainer } = props;+ const [selectedRoute, setSelectedRoute] = usePersistentState("route", "home");+ const isFocusModeEnabled = useAppStore(store => store.isFocusModeEnabled);+ const colors = useStore(store => store.colors);+ const isSideMenuOpen = useStore(store => store.isSideMenuOpen);++ useEffect(() => {+ RootNavigator.navigate(selectedRoute);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, []);++ return (+ <Animated.Flex+ flexDirection="column"+ justifyContent="space-between"+ initial={{ opacity: 1 }}+ animate={{+ opacity: isFocusModeEnabled ? 0 : 1,+ visibility: isFocusModeEnabled ? "hidden" : "visible"+ }}+ transition={{ duration: 0.3, ease: "easeOut" }}+ sx={{+ borderRight: "1px solid",+ borderRightColor: "primary",+ minWidth: ["85%", 50, 50],+ maxWidth: ["85%", 50, 50],+ display: [isSideMenuOpen ? "flex" : "none", "flex", "flex"],+ position: ["absolute", "relative", "relative"]+ }}+ bg={"background"}+ px={0}+ >+ <Box+ sx={{+ overflow: "scroll",+ scrollbarWidth: "none",+ "::-webkit-scrollbar": { width: 0, height: 0 },+ msOverflowStyle: "none"+ }}+ >+ {objectMap(routes, (_, item) => (+ <NavItem+ key={item.key}+ item={item}+ selected={selectedRoute === item.key}+ onSelected={() => {+ if (selectedRoute === item.key) toggleNavigationContainer();+ else if (RootNavigator.navigate(item.key))+ setSelectedRoute(item.key);+ }}+ />+ ))}+ {colors.map(color => {+ return (+ <NavItem+ onSelected={async () => {+ setSelectedRoute(undefined);+ RootNavigator.navigate("color", {+ title: toTitleCase(color.title),+ context: { type: "color", colors: [color.title] }+ });+ }}+ key={color.title}+ item={{+ color: COLORS[color.title],+ title: toTitleCase(color.title),+ icon: Icon.Circle,+ count: color.noteIds.length+ }}+ />+ );+ })}+ </Box>+ <Box>+ {Object.values(bottomRoutes).map(item => (+ <NavItem+ onSelected={async () => {+ const shouldSelect =+ (item.component && item.onClick && (await item.onClick())) ||+ RootNavigator.navigate(item.key);+ if (shouldSelect) setSelectedRoute(item.key);+ }}+ key={item.key}+ item={item}+ selected={selectedRoute === item.key}+ />+ ))}+ </Box>+ </Animated.Flex>+ );+}+export default NavigationMenu;diff --git a/apps/web/src/navigation/navigators/rootnavigator.js b/apps/web/src/navigation/navigators/rootnavigator.jsindex 15ce57eae..c6894a71f 100644--- a/apps/web/src/navigation/navigators/rootnavigator.js+++ b/apps/web/src/navigation/navigators/rootnavigator.js@@ -12,7 +12,6 @@ import { createRoute, createNormalRoute, createDeadRoute } from "../routes";import Navigator from "../index";import SelectionModeOptions from "../../common/selectionoptions";import Search from "../../views/Search";-import { store as noteStore } from "../../stores/note-store";import { store as userStore } from "../../stores/user-store";import { store as themeStore } from "../../stores/theme-store";import { showLogInDialog } from "../../components/dialogs/logindialog";@@ -29,8 +28,8 @@ export const bottomRoutes = {onClick: async () => {if (!userStore.getState().isLoggedIn) {await showLogInDialog();- }- RootNavigator.navigate("account");+ return false;+ } else return RootNavigator.navigate("account");}}),...createRoute("settings", SettingsContainer, {@@ -49,12 +48,7 @@ export const routes = {...createNormalRoute("favorites", Notes, Icon.StarOutline, {title: "Favorites",options: SelectionModeOptions.FavoritesOptions,- onClick: () => {- noteStore.getState().setSelectedContext({- type: "favorites"- });- RootNavigator.navigate("favorites");- }+ context: { type: "favorites" }}),...createNormalRoute("trash", Trash, Icon.Trash, {title: "Trash",