@@ -8,54 +8,38 @@ import { buttonVariants } from '@affine/admin/components/ui/button';
88import { cn } from '@affine/admin/utils' ;
99import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area' ;
1010import { ClipboardListIcon , SettingsIcon , UsersIcon } from 'lucide-react' ;
11- import { useEffect } from 'react' ;
12- import { Link } from 'react-router-dom' ;
11+ import { NavLink } from 'react-router-dom' ;
1312
1413import { useGetServerRuntimeConfig } from '../settings/use-get-server-runtime-config' ;
1514import { CollapsibleItem } from './collapsible-item' ;
1615import { useNav } from './context' ;
1716import { UserDropdown } from './user-dropdown' ;
1817
19- const TabsMap : { [ key : string ] : string } = {
20- accounts : 'Accounts' ,
21- ai : 'AI' ,
22- config : 'Config' ,
23- settings : 'Settings' ,
24- } ;
25-
2618export function Nav ( ) {
2719 const { moduleList } = useGetServerRuntimeConfig ( ) ;
28- const { activeTab, setActiveTab, setCurrentModule } = useNav ( ) ;
29-
30- useEffect ( ( ) => {
31- const path = window . location . pathname ;
32- for ( const key in TabsMap ) {
33- if ( path . includes ( key ) ) {
34- setActiveTab ( TabsMap [ key ] ) ;
35- return ;
36- }
37- }
38- } , [ setActiveTab ] ) ;
20+ const { setCurrentModule } = useNav ( ) ;
3921
4022 return (
4123 < div className = "flex flex-col gap-4 py-2 justify-between flex-grow overflow-hidden" >
4224 < nav className = "flex flex-col gap-1 px-2 flex-grow overflow-hidden" >
43- < Link
25+ < NavLink
4426 to = { '/admin/accounts' }
45- className = { cn (
46- buttonVariants ( {
47- variant : activeTab === 'Accounts' ? 'default' : 'ghost' ,
48- size : 'sm' ,
49- } ) ,
50- activeTab === 'Accounts' &&
51- 'dark:bg-muted dark:text-white dark:hover:bg-muted dark:hover:text-white' ,
52- 'justify-start' ,
53- 'flex-none'
54- ) }
27+ className = { ( { isActive } ) =>
28+ cn (
29+ buttonVariants ( {
30+ variant : isActive ? 'default' : 'ghost' ,
31+ size : 'sm' ,
32+ } ) ,
33+ isActive &&
34+ 'dark:bg-muted dark:text-white dark:hover:bg-muted dark:hover:text-white' ,
35+ 'justify-start' ,
36+ 'flex-none'
37+ )
38+ }
5539 >
5640 < UsersIcon className = "mr-2 h-4 w-4" />
5741 Accounts
58- </ Link >
42+ </ NavLink >
5943 { /* <Link
6044 to={'/admin/ai'}
6145 className={cn(
@@ -72,48 +56,55 @@ export function Nav() {
7256 <CpuIcon className="mr-2 h-4 w-4" />
7357 AI
7458 </Link> */ }
75- < Link
59+ < NavLink
7660 to = { '/admin/config' }
77- className = { cn (
78- buttonVariants ( {
79- variant : activeTab === 'Config' ? 'default' : 'ghost' ,
80- size : 'sm' ,
81- } ) ,
82- activeTab === 'Config' &&
83- 'dark:bg-muted dark:text-white dark:hover:bg-muted dark:hover:text-white' ,
84- 'justify-start' ,
85- 'flex-none'
86- ) }
61+ className = { ( { isActive } ) =>
62+ cn (
63+ buttonVariants ( {
64+ variant : isActive ? 'default' : 'ghost' ,
65+ size : 'sm' ,
66+ } ) ,
67+ isActive &&
68+ 'dark:bg-muted dark:text-white dark:hover:bg-muted dark:hover:text-white' ,
69+ 'justify-start' ,
70+ 'flex-none'
71+ )
72+ }
8773 >
8874 < ClipboardListIcon className = "mr-2 h-4 w-4" />
8975 Config
90- </ Link >
76+ </ NavLink >
9177
9278 < Accordion type = "multiple" className = "w-full h-full overflow-hidden" >
9379 < AccordionItem
9480 value = "item-1"
95- className = "border-b-0 h-full flex flex-col gap-1"
81+ className = "border-b-0 h-full flex flex-col gap-1 w-full "
9682 >
97- < Link to = { '/admin/settings' } >
98- < AccordionTrigger
99- className = { cn (
83+ < NavLink
84+ to = { '/admin/settings' }
85+ className = { ( { isActive } ) =>
86+ cn (
10087 buttonVariants ( {
101- variant : activeTab === 'Settings' ? 'default' : 'ghost' ,
88+ variant : isActive ? 'default' : 'ghost' ,
10289 size : 'sm' ,
10390 } ) ,
104-
105- activeTab === 'Settings' &&
91+ isActive &&
10692 'dark:bg-muted dark:text-white dark:hover:bg-muted dark:hover:text-white' ,
107- 'justify-between' ,
108- 'hover:no-underline'
109- ) }
93+ 'justify-start' ,
94+ 'flex-none' ,
95+ 'w-full'
96+ )
97+ }
98+ >
99+ < AccordionTrigger
100+ className = { 'flex items-center justify-between w-full' }
110101 >
111102 < div className = "flex items-center" >
112103 < SettingsIcon className = "mr-2 h-4 w-4" />
113104 < span > Settings</ span >
114105 </ div >
115106 </ AccordionTrigger >
116- </ Link >
107+ </ NavLink >
117108
118109 < AccordionContent className = "h-full overflow-hidden w-full" >
119110 < ScrollAreaPrimitive . Root
0 commit comments