@@ -11,13 +11,13 @@ import {
1111 SidebarMenuItem ,
1212 SidebarTrigger ,
1313} from '@/components/ui/sidebar' ;
14- import { Home , Package , SquareKanban } from 'lucide-react' ;
14+ import { Home , SquareKanban } from 'lucide-react' ;
1515
1616interface SidebarItem {
1717 key : string ;
1818 label : string ;
1919 icon : React . ReactNode ;
20- path : string ;
20+ onClick ?: ( ) => void ;
2121}
2222
2323export function NavigationSidebar ( ) {
@@ -37,98 +37,48 @@ export function NavigationSidebar() {
3737 return false ;
3838 } ;
3939
40- // Get contextual menu items based on current path
41- const getMenuItems = ( ) => {
42- if ( ! mounted ) return [ ] ;
43-
44- const pathParts = pathname . split ( '/' ) . filter ( Boolean ) ;
45-
46- // Overview page (/)
47- if ( pathname === '/' ) {
48- return [
49- {
50- key : 'projects' ,
51- label : 'Projects' ,
52- icon : < Package size = { 16 } /> ,
53- } ,
54- ] ;
55- }
56-
57- // Projects page (/projects)
58- if ( pathname === '/projects' ) {
59- return [
60- {
61- key : 'projects' ,
62- label : 'Projects' ,
63- icon : < Package size = { 16 } /> ,
64- } ,
65- ] ;
40+ const getProjectId = ( ) => {
41+ const matched = pathname . match ( / \/ p r o j e c t s \/ ( \w + ) / ) ;
42+ if ( matched ) {
43+ return matched [ 1 ] ;
6644 }
45+ return null ;
46+ } ;
6747
68- if ( pathname . match ( / ^ \/ p r o j e c t s \/ \w + \/ d e v l o g s / ) ) {
69- }
48+ const projectsMenuItems = [
49+ {
50+ key : 'overview' ,
51+ label : 'Overview' ,
52+ icon : < Home size = { 16 } /> ,
53+ onClick : ( ) => router . push ( '/projects' ) ,
54+ } ,
55+ ] ;
56+ const projectDetailMenuItems = [
57+ {
58+ key : 'overview' ,
59+ label : 'Overview' ,
60+ icon : < Home size = { 16 } /> ,
61+ onClick : ( ) => router . push ( `/projects/${ getProjectId ( ) } ` ) ,
62+ } ,
63+ {
64+ key : 'list' ,
65+ label : 'Devlogs' ,
66+ icon : < SquareKanban size = { 16 } /> ,
67+ onClick : ( ) => router . push ( `/projects/${ getProjectId ( ) } /devlogs` ) ,
68+ } ,
69+ ] ;
7070
71- // Project detail page (/projects/[id])
72- if ( pathParts . length === 2 && pathParts [ 0 ] === 'projects' ) {
73- return [
74- {
75- key : 'overview' ,
76- label : 'Overview' ,
77- icon : < Home size = { 16 } /> ,
78- } ,
79- {
80- key : 'list' ,
81- label : 'Devlogs' ,
82- icon : < SquareKanban size = { 16 } /> ,
83- } ,
84- ] ;
85- }
71+ // Get contextual menu items based on current path
72+ const getMenuItems = ( ) : SidebarItem [ ] => {
73+ if ( ! mounted ) return [ ] ;
8674
87- // Project devlogs page (/projects/[id]/devlogs)
88- if ( pathParts . length === 3 && pathParts [ 0 ] === 'projects' && pathParts [ 2 ] === 'devlogs' ) {
89- return [
90- {
91- key : 'overview' ,
92- label : 'Overview' ,
93- icon : < Home size = { 16 } /> ,
94- } ,
95- {
96- key : 'list' ,
97- label : 'Devlogs' ,
98- icon : < SquareKanban size = { 16 } /> ,
99- } ,
100- ] ;
101- }
75+ const pathParts = pathname . split ( '/' ) . filter ( Boolean ) ;
10276
103- // Devlog detail page (/projects/[id]/devlogs/[devlogId])
104- if ( pathParts . length === 4 && pathParts [ 0 ] === 'projects' && pathParts [ 2 ] === 'devlogs' ) {
105- return [
106- {
107- key : 'overview' ,
108- label : 'Overview' ,
109- icon : < Home size = { 16 } /> ,
110- } ,
111- {
112- key : 'list' ,
113- label : 'Devlogs' ,
114- icon : < SquareKanban size = { 16 } /> ,
115- } ,
116- ] ;
77+ if ( pathParts . length < 2 ) {
78+ return projectsMenuItems ;
79+ } else {
80+ return projectDetailMenuItems ;
11781 }
118-
119- // Default fallback
120- return [
121- {
122- key : 'overview' ,
123- label : 'Overview' ,
124- icon : < Home size = { 16 } /> ,
125- } ,
126- {
127- key : 'projects' ,
128- label : 'Projects' ,
129- icon : < Package size = { 16 } /> ,
130- } ,
131- ] ;
13282 } ;
13383
13484 // Determine selected key based on current pathname and menu items
@@ -161,6 +111,7 @@ export function NavigationSidebar() {
161111 < SidebarMenuButton
162112 isActive = { getSelectedKey ( ) === item . key }
163113 className = "flex items-center gap-3 px-4 py-3 text-sm font-medium min-h-[44px] rounded-md"
114+ onClick = { item . onClick }
164115 >
165116 { item . icon }
166117 < span > { item . label } </ span >
0 commit comments