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
web: fix navigation commands in command palette (#8070)
01zulfie3a973d61e03
diff --git a/apps/web/src/components/navigation-menu/index.tsx b/apps/web/src/components/navigation-menu/index.tsxindex 01a3bfec4..63bfc41d0 100644--- a/apps/web/src/components/navigation-menu/index.tsx+++ b/apps/web/src/components/navigation-menu/index.tsx@@ -21,10 +21,8 @@ import React, { useEffect, useMemo, useRef, useState } from "react";import { Box, Button, Flex, Image, Text } from "@theme-ui/components";import {Note,- Notebook as NotebookIcon,StarOutline,Monographs,- Tag as TagIcon,Trash,Settings,Notebook2,@@ -37,17 +35,19 @@ import {Icon,Reminders,User,- Home,Pro,Documentation,Logout,- Plus,- SortBy,Reset,Rename,ExpandSidebar,HamburgerMenu,- Archive+ Archive,+ Home,+ Notebook as NotebookIcon,+ Plus,+ SortBy,+ Tag as TagIcon} from "../icons";import { SortableNavigationItem } from "./navigation-item";import {@@ -67,8 +67,6 @@ import { useStore as useNoteStore } from "../../stores/note-store";import { useStore as useReminderStore } from "../../stores/reminder-store";import { useStore as useMonographStore } from "../../stores/monograph-store";import { useStore as useTrashStore } from "../../stores/trash-store";-import { useStore as useNotebookStore } from "../../stores/notebook-store";-import { useStore as useTagStore } from "../../stores/tag-store";import { useStore as useSearchStore } from "../../stores/search-store";import useLocation from "../../hooks/use-location";import { FlexScrollContainer } from "../scroll-container";@@ -100,16 +98,14 @@ import Tags from "../../views/tags";import { Notebooks } from "../../views/notebooks";import { UserProfile } from "../../dialogs/settings/components/user-profile";import { SUBSCRIPTION_STATUS } from "../../common/constants";-import {- CREATE_BUTTON_MAP,- createSetDefaultHomepageMenuItem,- logout-} from "../../common";+import { createSetDefaultHomepageMenuItem, logout } from "../../common";import { TabItem } from "./tab-item";import Notice from "../notice";-import { usePromise } from "@notesnook/common";-import { showSortMenu } from "../group-header";import { Freeze } from "react-freeze";+import { CREATE_BUTTON_MAP } from "../../common";+import { useStore as useNotebookStore } from "../../stores/notebook-store";+import { useStore as useTagStore } from "../../stores/tag-store";+import { showSortMenu } from "../group-header";type Route = {id: "notes" | "favorites" | "reminders" | "monographs" | "trash" | "archive";@@ -148,7 +144,26 @@ const routes: Route[] = [}];-const tabs = [+const settings = {+ id: "settings",+ title: strings.routes.Settings(),+ path: "/settings",+ icon: Settings+} as const;++export type NavigationTabItem = {+ id: "home" | "notebooks" | "tags";+ icon: Icon;+ title: string;+ actions: {+ id: string;+ title: string;+ icon: Icon;+ onClick: () => void;+ }[];+};++const tabs: NavigationTabItem[] = [{id: "home",icon: Home,@@ -197,30 +212,22 @@ const tabs = [}] as const;-const settings = {- id: "settings",- title: strings.routes.Settings(),- path: "/settings",- icon: Settings-} as const;-function NavigationMenu({ onExpand }: { onExpand?: () => void }) {const isFocusMode = useAppStore((store) => store.isFocusMode);- const [currentTab, setCurrentTab] = useState<(typeof tabs)[number]>(() => {- const defaultSidebarTab = useSettingStore.getState().defaultSidebarTab;- return tabs.find((tab) => tab.id === defaultSidebarTab) || tabs[0];- });+ const navigationTab = useAppStore((store) => store.navigationTab);+ const setNavigationTab = useAppStore((store) => store.setNavigationTab);const isNavPaneCollapsed = useAppStore((store) => store.isNavPaneCollapsed);const [expanded, setExpanded] = useState(false);const isCollapsed = isNavPaneCollapsed && !expanded;const mouseHoverTimeout = useRef(0);+ const currentTab = tabs.find((tab) => tab.id === navigationTab) || tabs[0];useEffect(() => {if (isNavPaneCollapsed) setExpanded(false);}, [isNavPaneCollapsed]);useEffect(() => {- function onNavigate() {+ function onNavigate(_, location: string) {// collapse navigation menu on navigate e.g. when navigating to a notebook// or a tagif (!useAppStore.getState().isNavPaneCollapsed) return;@@ -351,7 +358,7 @@ function NavigationMenu({ onExpand }: { onExpand?: () => void }) {selected={currentTab.id === tab.id}onClick={() => {if (isNavPaneCollapsed) setExpanded(true);- setCurrentTab(tab);+ setNavigationTab(tab.id);}}/>))}diff --git a/apps/web/src/dialogs/command-palette/commands.ts b/apps/web/src/dialogs/command-palette/commands.tsindex 0d8412ddc..3bf215cd4 100644--- a/apps/web/src/dialogs/command-palette/commands.ts+++ b/apps/web/src/dialogs/command-palette/commands.ts@@ -72,8 +72,14 @@ export const commandActions = {command: (command: Command) => getCommandById(command.id)?.action(command),note: (command: Command, options?: { openInNewTab?: boolean }) =>useEditorStore.getState().openSession(command.id, options),- notebook: (command: Command) => navigate(`/notebooks/${command.id}`),- tag: (command: Command) => navigate(`/tags/${command.id}`),+ notebook: (command: Command) => {+ useAppStore.getState().setNavigationTab("notebooks");+ navigate(`/notebooks/${command.id}`);+ },+ tag: (command: Command) => {+ useAppStore.getState().setNavigationTab("tags");+ navigate(`/tags/${command.id}`);+ },reminder: (command: Command) => hashNavigate(`/reminders/${command.id}/edit`)};@@ -92,7 +98,10 @@ const staticCommands: Command[] = [id: "notes",title: strings.dataTypesPluralCamelCase.note(),icon: ArrowTopRight,- action: () => navigate("/"),+ action: () => {+ useAppStore.getState().setNavigationTab("home");+ navigate("/");+ },group: strings.navigate(),type: "command"},@@ -100,7 +109,7 @@ const staticCommands: Command[] = [id: "notebooks",title: strings.dataTypesPluralCamelCase.notebook(),icon: ArrowTopRight,- action: () => navigate("/notebooks"),+ action: () => useAppStore.getState().setNavigationTab("notebooks"),group: strings.navigate(),type: "command"},@@ -108,7 +117,7 @@ const staticCommands: Command[] = [id: "tags",title: strings.dataTypesPluralCamelCase.tag(),icon: ArrowTopRight,- action: () => navigate("/tags"),+ action: () => useAppStore.getState().setNavigationTab("tags"),group: strings.navigate(),type: "command"},@@ -116,7 +125,10 @@ const staticCommands: Command[] = [id: "favorites",title: strings.dataTypesPluralCamelCase.favorite(),icon: ArrowTopRight,- action: () => navigate("/favorites"),+ action: () => {+ useAppStore.getState().setNavigationTab("home");+ navigate("/favorites");+ },group: strings.navigate(),type: "command"},@@ -124,7 +136,10 @@ const staticCommands: Command[] = [id: "reminders",title: strings.dataTypesPluralCamelCase.reminder(),icon: ArrowTopRight,- action: () => navigate("/reminders"),+ action: () => {+ useAppStore.getState().setNavigationTab("home");+ navigate("/reminders");+ },group: strings.navigate(),type: "command"},@@ -132,7 +147,10 @@ const staticCommands: Command[] = [id: "monographs",title: strings.dataTypesPluralCamelCase.monograph(),icon: ArrowTopRight,- action: () => navigate("/monographs"),+ action: () => {+ useAppStore.getState().setNavigationTab("home");+ navigate("/monographs");+ },group: strings.navigate(),type: "command"},@@ -140,7 +158,10 @@ const staticCommands: Command[] = [id: "trash",title: strings.trash(),icon: ArrowTopRight,- action: () => navigate("/trash"),+ action: () => {+ useAppStore.getState().setNavigationTab("home");+ navigate("/trash");+ },group: strings.navigate(),type: "command"},diff --git a/apps/web/src/stores/app-store.ts b/apps/web/src/stores/app-store.tsindex cef476c27..9f1671c50 100644--- a/apps/web/src/stores/app-store.ts+++ b/apps/web/src/stores/app-store.ts@@ -26,7 +26,6 @@ import { store as tagStore } from "./tag-store";import { store as attachmentStore } from "./attachment-store";import { store as monographStore } from "./monograph-store";import { store as reminderStore } from "./reminder-store";-import { store as announcementStore } from "./announcement-store";import { store as settingStore } from "./setting-store";import BaseStore from "./index";import { showToast } from "../utils/toast";@@ -44,6 +43,7 @@ import { strings } from "@notesnook/intl";import { useEditorStore } from "./editor-store";import { useEditorManager } from "../components/editor/manager";import { exitFullscreen } from "../utils/fullscreen";+import { NavigationTabItem } from "../components/navigation-menu";type SyncState =| "synced"@@ -82,6 +82,7 @@ class AppStore extends BaseStore<AppStore> {notices: Notice[] = [];shortcuts: (Notebook | Tag)[] = [];lastSynced = 0;+ navigationTab: NavigationTabItem["id"] = settingStore.get().defaultSidebarTab;init = () => {this.refresh();@@ -368,6 +369,10 @@ class AppStore extends BaseStore<AppStore> {const status = this.get().syncStatus.key;return status === "syncing";};++ setNavigationTab = (tab: NavigationTabItem["id"]) => {+ this.set((state) => (state.navigationTab = tab));+ };}const [useStore, store] = createStore<AppStore>(