From 2fccd1f3de690c98a7d149e3689fa02a5702fee4 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 23 May 2026 16:26:35 +0000 Subject: [PATCH] Optimize settings sidebar nav renders Co-authored-by: Julius Marminge --- .../settings/SettingsSidebarNav.items.ts | 32 +++++++++ .../settings/SettingsSidebarNav.tsx | 70 ++++--------------- .../settings/SettingsSidebarNavItem.tsx | 45 ++++++++++++ 3 files changed, 89 insertions(+), 58 deletions(-) create mode 100644 apps/web/src/components/settings/SettingsSidebarNav.items.ts create mode 100644 apps/web/src/components/settings/SettingsSidebarNavItem.tsx diff --git a/apps/web/src/components/settings/SettingsSidebarNav.items.ts b/apps/web/src/components/settings/SettingsSidebarNav.items.ts new file mode 100644 index 0000000000..4e341f97ee --- /dev/null +++ b/apps/web/src/components/settings/SettingsSidebarNav.items.ts @@ -0,0 +1,32 @@ +import { + ArchiveIcon, + BotIcon, + GitBranchIcon, + KeyboardIcon, + Link2Icon, + Settings2Icon, +} from "lucide-react"; +import type { ComponentType } from "react"; + +export type SettingsSectionPath = + | "/settings/general" + | "/settings/keybindings" + | "/settings/providers" + | "/settings/source-control" + | "/settings/connections" + | "/settings/archived"; + +export interface SettingsNavItem { + readonly icon: ComponentType<{ className?: string }>; + readonly label: string; + readonly to: SettingsSectionPath; +} + +export const SETTINGS_NAV_ITEMS: ReadonlyArray = [ + { label: "General", to: "/settings/general", icon: Settings2Icon }, + { label: "Keybindings", to: "/settings/keybindings", icon: KeyboardIcon }, + { label: "Providers", to: "/settings/providers", icon: BotIcon }, + { label: "Source Control", to: "/settings/source-control", icon: GitBranchIcon }, + { label: "Connections", to: "/settings/connections", icon: Link2Icon }, + { label: "Archive", to: "/settings/archived", icon: ArchiveIcon }, +]; diff --git a/apps/web/src/components/settings/SettingsSidebarNav.tsx b/apps/web/src/components/settings/SettingsSidebarNav.tsx index bec9606386..10e2ac4637 100644 --- a/apps/web/src/components/settings/SettingsSidebarNav.tsx +++ b/apps/web/src/components/settings/SettingsSidebarNav.tsx @@ -1,13 +1,5 @@ -import { useCallback, type ComponentType } from "react"; -import { - ArchiveIcon, - ArrowLeftIcon, - BotIcon, - GitBranchIcon, - KeyboardIcon, - Link2Icon, - Settings2Icon, -} from "lucide-react"; +import { useCallback } from "react"; +import { ArrowLeftIcon } from "lucide-react"; import { useCanGoBack, useNavigate } from "@tanstack/react-router"; import { @@ -20,27 +12,8 @@ import { SidebarSeparator, useSidebar, } from "../ui/sidebar"; - -export type SettingsSectionPath = - | "/settings/general" - | "/settings/keybindings" - | "/settings/providers" - | "/settings/source-control" - | "/settings/connections" - | "/settings/archived"; - -export const SETTINGS_NAV_ITEMS: ReadonlyArray<{ - label: string; - to: SettingsSectionPath; - icon: ComponentType<{ className?: string }>; -}> = [ - { label: "General", to: "/settings/general", icon: Settings2Icon }, - { label: "Keybindings", to: "/settings/keybindings", icon: KeyboardIcon }, - { label: "Providers", to: "/settings/providers", icon: BotIcon }, - { label: "Source Control", to: "/settings/source-control", icon: GitBranchIcon }, - { label: "Connections", to: "/settings/connections", icon: Link2Icon }, - { label: "Archive", to: "/settings/archived", icon: ArchiveIcon }, -]; +import { SETTINGS_NAV_ITEMS, type SettingsSectionPath } from "./SettingsSidebarNav.items"; +import { SettingsSidebarNavItem } from "./SettingsSidebarNavItem"; export function SettingsSidebarNav({ pathname }: { pathname: string }) { const navigate = useNavigate(); @@ -71,33 +44,14 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) { - {SETTINGS_NAV_ITEMS.map((item) => { - const Icon = item.icon; - const isActive = pathname === item.to; - return ( - - handleSectionClick(item.to)} - > - - {item.label} - - - ); - })} + {SETTINGS_NAV_ITEMS.map((item) => ( + + ))} diff --git a/apps/web/src/components/settings/SettingsSidebarNavItem.tsx b/apps/web/src/components/settings/SettingsSidebarNavItem.tsx new file mode 100644 index 0000000000..c634752a2c --- /dev/null +++ b/apps/web/src/components/settings/SettingsSidebarNavItem.tsx @@ -0,0 +1,45 @@ +import { memo, useCallback } from "react"; + +import { SidebarMenuButton, SidebarMenuItem } from "../ui/sidebar"; +import type { SettingsNavItem, SettingsSectionPath } from "./SettingsSidebarNav.items"; + +interface SettingsSidebarNavItemProps { + readonly isActive: boolean; + readonly item: SettingsNavItem; + readonly onSelect: (to: SettingsSectionPath) => void; +} + +export const SettingsSidebarNavItem = memo(function SettingsSidebarNavItem({ + isActive, + item, + onSelect, +}: SettingsSidebarNavItemProps) { + const Icon = item.icon; + const handleClick = useCallback(() => { + onSelect(item.to); + }, [item.to, onSelect]); + + return ( + + + + {item.label} + + + ); +});