Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

refactor: Unifiy the metadata between desktop app and CMDK (#11602)

René Wangfd2e3a305d17
diff --git a/src/app/[variants]/(main)/home/_layout/Body/BottomMenu/index.tsx b/src/app/[variants]/(main)/home/_layout/Body/BottomMenu/index.tsx
index ff452ecd8b1..38621bd629a 100644
--- a/src/app/[variants]/(main)/home/_layout/Body/BottomMenu/index.tsx
+++ b/src/app/[variants]/(main)/home/_layout/Body/BottomMenu/index.tsx
@@ -1,9 +1,9 @@
import { Flexbox } from '@lobehub/ui';
-import { BrainCircuit, LibraryBigIcon, Settings } from 'lucide-react';
import { memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { Link, useNavigate } from 'react-router-dom';
+import { getRouteById } from '@/config/routes';
import NavItem from '@/features/NavPanel/components/NavItem';
import { useActiveTabKey } from '@/hooks/useActiveTabKey';
import { SidebarTabKey } from '@/store/global/initialState';
@@ -25,19 +25,19 @@ const BottomMenu = memo(() => {
() =>
[
{
- icon: Settings,
+ icon: getRouteById('settings')!.icon,
key: SidebarTabKey.Setting,
title: t('tab.setting'),
url: '/settings',
},
{
- icon: LibraryBigIcon,
+ icon: getRouteById('resource')!.icon,
key: SidebarTabKey.Resource,
title: t('tab.resource'),
url: '/resource',
},
{
- icon: BrainCircuit,
+ icon: getRouteById('memory')!.icon,
key: SidebarTabKey.Memory,
title: t('tab.memory'),
url: '/memory',
diff --git a/src/app/[variants]/(main)/home/_layout/Header/components/Nav.tsx b/src/app/[variants]/(main)/home/_layout/Header/components/Nav.tsx
index 5dfe6bbd836..a217f7f0696 100644
--- a/src/app/[variants]/(main)/home/_layout/Header/components/Nav.tsx
+++ b/src/app/[variants]/(main)/home/_layout/Header/components/Nav.tsx
@@ -1,11 +1,12 @@
'use client';
import { Flexbox } from '@lobehub/ui';
-import { FilePenIcon, HomeIcon, ImageIcon, SearchIcon, ShapesIcon } from 'lucide-react';
+import { HomeIcon, SearchIcon } from 'lucide-react';
import { memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { Link, useNavigate } from 'react-router-dom';
+import { getRouteById } from '@/config/routes';
import { useActiveTabKey } from '@/hooks/useActiveTabKey';
import { useGlobalStore } from '@/store/global';
import { SidebarTabKey } from '@/store/global/initialState';
@@ -48,21 +49,21 @@ const Nav = memo(() => {
url: '/',
},
{
- icon: FilePenIcon,
+ icon: getRouteById('page')!.icon,
key: SidebarTabKey.Pages,
title: t('tab.pages'),
url: '/page',
},
{
hidden: !showAiImage,
- icon: ImageIcon,
+ icon: getRouteById('image')!.icon,
key: SidebarTabKey.Image,
title: t('tab.aiImage'),
url: '/image',
},
{
hidden: !showMarket,
- icon: ShapesIcon,
+ icon: getRouteById('community')!.icon,
key: SidebarTabKey.Community,
title: t('tab.community'),
url: '/community',
diff --git a/src/config/routes/index.ts b/src/config/routes/index.ts
new file mode 100644
index 00000000000..98ae775957e
--- /dev/null
+++ b/src/config/routes/index.ts
@@ -0,0 +1,104 @@
+import {
+ BrainCircuit,
+ FilePenIcon,
+ Image,
+ LibraryBigIcon,
+ type LucideIcon,
+ Settings,
+ ShapesIcon,
+} from 'lucide-react';
+
+export interface NavigationRoute {
+ /** CMDK i18n key in common namespace */
+ cmdkKey: string;
+ /** Electron i18n key in electron namespace */
+ electronKey: string;
+ /** Route icon component */
+ icon: LucideIcon;
+ /** Unique route identifier */
+ id: string;
+ /** Keywords for CMDK search */
+ keywords?: string[];
+ /** Route path */
+ path: string;
+ /** Path prefix for checking current location */
+ pathPrefix: string;
+ /** Whether route supports dynamic titles (for specific items) */
+ useDynamicTitle?: boolean;
+}
+
+/**
+ * Shared navigation route configuration
+ * Used by both Electron navigation and CommandMenu (CMDK)
+ */
+export const NAVIGATION_ROUTES: NavigationRoute[] = [
+ {
+ cmdkKey: 'cmdk.community',
+ electronKey: 'navigation.discover',
+ icon: ShapesIcon,
+ id: 'community',
+ keywords: ['discover', 'market', 'assistant', 'model', 'provider', 'mcp'],
+ path: '/community',
+ pathPrefix: '/community',
+ },
+ {
+ cmdkKey: 'cmdk.painting',
+ electronKey: 'navigation.image',
+ icon: Image,
+ id: 'image',
+ keywords: ['painting', 'art', 'generate', 'draw'],
+ path: '/image',
+ pathPrefix: '/image',
+ },
+ {
+ cmdkKey: 'cmdk.resource',
+ electronKey: 'navigation.resources',
+ icon: LibraryBigIcon,
+ id: 'resource',
+ keywords: ['knowledge', 'files', 'library', 'documents'],
+ path: '/resource',
+ pathPrefix: '/resource',
+ },
+ {
+ cmdkKey: 'cmdk.pages',
+ electronKey: 'navigation.pages',
+ icon: FilePenIcon,
+ id: 'page',
+ keywords: ['documents', 'write', 'notes'],
+ path: '/page',
+ pathPrefix: '/page',
+ useDynamicTitle: true,
+ },
+ {
+ cmdkKey: 'cmdk.memory',
+ electronKey: 'navigation.memory',
+ icon: BrainCircuit,
+ id: 'memory',
+ keywords: ['identities', 'contexts', 'preferences', 'experiences'],
+ path: '/memory',
+ pathPrefix: '/memory',
+ },
+ {
+ cmdkKey: 'cmdk.settings',
+ electronKey: 'navigation.settings',
+ icon: Settings,
+ id: 'settings',
+ keywords: ['settings', 'preferences', 'configuration', 'options'],
+ path: '/settings',
+ pathPrefix: '/settings',
+ },
+];
+
+/**
+ * Get route configuration by id
+ */
+export const getRouteById = (id: string): NavigationRoute | undefined =>
+ NAVIGATION_ROUTES.find((r) => r.id === id);
+
+/**
+ * Get navigable routes for CMDK (excludes settings which has separate handling)
+ */
+export const getNavigableRoutes = (): NavigationRoute[] =>
+ NAVIGATION_ROUTES.filter((r) =>
+ ['community', 'image', 'resource', 'page', 'memory'].includes(r.id),
+ );
diff --git a/src/features/CommandMenu/MainMenu.tsx b/src/features/CommandMenu/MainMenu.tsx
index 947f49e1c32..0de95768235 100644
--- a/src/features/CommandMenu/MainMenu.tsx
+++ b/src/features/CommandMenu/MainMenu.tsx
@@ -3,21 +3,18 @@ import { DiscordIcon } from '@lobehub/ui/icons';
import { Command } from 'cmdk';
import {
Bot,
- BrainCircuit,
FilePen,
Github,
- Image,
LibraryBig,
MailIcon,
MessageSquarePlusIcon,
Monitor,
- Settings,
- Shapes,
Star,
} from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
+import { getNavigableRoutes, getRouteById } from '@/config/routes';
import { FEEDBACK } from '@/const/url';
import { useFeedbackModal } from '@/hooks/useFeedbackModal';
@@ -88,16 +85,20 @@ const MainMenu = memo(() => {
{t('cmdk.newLibrary')}
</CommandItem>
- {menuContext !== 'settings' && (
- <CommandItem
- icon={<Settings />}
- keywords={['settings', 'preferences', 'configuration', 'options']}
- onSelect={() => handleNavigate('/settings')}
- value="settings"
- >
- {t('cmdk.settings')}
- </CommandItem>
- )}
+ {menuContext !== 'settings' && (() => {
+ const settingsRoute = getRouteById('settings');
+ const SettingsIcon = settingsRoute?.icon;
+ return (
+ <CommandItem
+ icon={SettingsIcon && <SettingsIcon />}
+ keywords={settingsRoute?.keywords}
+ onSelect={() => handleNavigate(settingsRoute?.path || '/settings')}
+ value="settings"
+ >
+ {t('cmdk.settings')}
+ </CommandItem>
+ );
+ })()}
<CommandItem
icon={<Monitor />}
@@ -109,47 +110,22 @@ const MainMenu = memo(() => {
</Command.Group>
<Command.Group heading={t('cmdk.navigate')}>
- {!pathname?.startsWith('/community') && (
- <CommandItem
- icon={<Shapes />}
- onSelect={() => handleNavigate('/community')}
- value="community"
- >
- {t('cmdk.community')}
- </CommandItem>
- )}
- {!pathname?.startsWith('/image') && (
- <CommandItem icon={<Image />} onSelect={() => handleNavigate('/image')} value="painting">
- {t('cmdk.painting')}
- </CommandItem>
- )}
- {!pathname?.startsWith('/knowledge') && (
- <CommandItem
- icon={<LibraryBig />}
- onSelect={() => handleNavigate('/resource')}
- value="resource"
- >
- {t('cmdk.resource')}
- </CommandItem>
- )}
- {!pathname?.startsWith('/page') && (
- <CommandItem
- icon={<FilePen />}
- onSelect={() => handleNavigate('/page')}
- value="page documents write"
- >
- {t('cmdk.pages')}
- </CommandItem>
- )}
- {!pathname?.startsWith('/memory') && (
- <CommandItem
- icon={<BrainCircuit />}
- onSelect={() => handleNavigate('/memory')}
- value="memory"
- >
- {t('cmdk.memory')}
- </CommandItem>
- )}
+ {getNavigableRoutes().map((route) => {
+ const RouteIcon = route.icon;
+ return (
+ !pathname?.startsWith(route.pathPrefix) && (
+ <CommandItem
+ icon={<RouteIcon />}
+ key={route.id}
+ keywords={route.keywords}
+ onSelect={() => handleNavigate(route.path)}
+ value={route.id}
+ >
+ {t(route.cmdkKey as any)}
+ </CommandItem>
+ )
+ );
+ })}
</Command.Group>
<Command.Group heading={t('cmdk.about')}>
diff --git a/src/features/Electron/navigation/routeMetadata.ts b/src/features/Electron/navigation/routeMetadata.ts
index 515890d4212..85f1a102cbf 100644
--- a/src/features/Electron/navigation/routeMetadata.ts
+++ b/src/features/Electron/navigation/routeMetadata.ts
@@ -3,20 +3,17 @@
* Provides title and icon information based on route path
*/
import {
- Brain,
Circle,
- Compass,
- Database,
- FileText,
Home,
- Image,
type LucideIcon,
MessageSquare,
Rocket,
- Settings,
+ ShapesIcon,
Users,
} from 'lucide-react';
+import { getRouteById } from '@/config/routes';
+
export interface RouteMetadata {
icon?: LucideIcon;
/** i18n key for the title (namespace: electron) */
@@ -34,18 +31,26 @@ interface RoutePattern {
useDynamicTitle?: boolean;
}
+// Get shared icons
+const communityIcon = getRouteById('community')?.icon;
+const resourceIcon = getRouteById('resource')?.icon;
+const memoryIcon = getRouteById('memory')?.icon;
+const imageIcon = getRouteById('image')?.icon;
+const pageIcon = getRouteById('page')?.icon;
+const settingsIcon = getRouteById('settings')?.icon;
+
/**
* Route patterns ordered by specificity (most specific first)
*/
const routePatterns: RoutePattern[] = [
// Settings routes
{
- icon: Settings,
+ icon: settingsIcon,
test: (p) => p.startsWith('/settings/provider'),
titleKey: 'navigation.provider',
},
{
- icon: Settings,
+ icon: settingsIcon,
test: (p) => p.startsWith('/settings'),
titleKey: 'navigation.settings',
},
@@ -78,86 +83,86 @@ const routePatterns: RoutePattern[] = [
// Community/Discover routes
{
- icon: Compass,
+ icon: ShapesIcon,
test: (p) => p.startsWith('/community/agent'),
titleKey: 'navigation.discoverAssistants',
},
{
- icon: Compass,
+ icon: communityIcon,
test: (p) => p.startsWith('/community/model'),
titleKey: 'navigation.discoverModels',
},
{
- icon: Compass,
+ icon: communityIcon,
test: (p) => p.startsWith('/community/provider'),
titleKey: 'navigation.discoverProviders',
},
{
- icon: Compass,
+ icon: communityIcon,
test: (p) => p.startsWith('/community/mcp'),
titleKey: 'navigation.discoverMcp',
},
{
- icon: Compass,
+ icon: communityIcon,
test: (p) => p.startsWith('/community'),
titleKey: 'navigation.discover',
},
// Resource/Knowledge routes
{
- icon: Database,
+ icon: resourceIcon,
test: (p) => p.startsWith('/resource/library'),
titleKey: 'navigation.knowledgeBase',
},
{
- icon: Database,
+ icon: resourceIcon,
test: (p) => p.startsWith('/resource'),
titleKey: 'navigation.resources',
},
// Memory routes
{
- icon: Brain,
+ icon: memoryIcon,
test: (p) => p.startsWith('/memory/identities'),
titleKey: 'navigation.memoryIdentities',
},
{
- icon: Brain,
+ icon: memoryIcon,
test: (p) => p.startsWith('/memory/contexts'),
titleKey: 'navigation.memoryContexts',
},
{
- icon: Brain,
+ icon: memoryIcon,
test: (p) => p.startsWith('/memory/preferences'),
titleKey: 'navigation.memoryPreferences',
},
{
- icon: Brain,
+ icon: memoryIcon,
test: (p) => p.startsWith('/memory/experiences'),
titleKey: 'navigation.memoryExperiences',
},
{
- icon: Brain,
+ icon: memoryIcon,
test: (p) => p.startsWith('/memory'),
titleKey: 'navigation.memory',
},
// Image routes
{
- icon: Image,
+ icon: imageIcon,
test: (p) => p.startsWith('/image'),
titleKey: 'navigation.image',
},
// Page routes - use dynamic title for specific page names
{
- icon: FileText,
+ icon: pageIcon,
test: (p) => p.startsWith('/page/'),
titleKey: 'navigation.page',
useDynamicTitle: true,
},
{
- icon: FileText,
+ icon: pageIcon,
test: (p) => p === '/page',
titleKey: 'navigation.pages',
},