@@ -20,14 +20,34 @@ import { Skeleton } from '@/components/ui/skeleton';
2020import { toast } from 'sonner' ;
2121
2222export function NavigationBreadcrumb ( ) {
23- const router = useRouter ( ) ;
2423 const pathname = usePathname ( ) ;
24+ const router = useRouter ( ) ;
25+
26+ // Parse project name and devlog ID from URL instead of using context hooks
27+ // since this component is rendered at app level, outside of the provider hierarchy
28+ const pathSegments = pathname . split ( '/' ) . filter ( Boolean ) ;
29+ let projectName : string | null = null ;
30+ let devlogId : number | null = null ;
31+
32+ // Check if we're in a project path: /projects/[name] or /projects/[name]/devlogs/[id]
33+ if ( pathSegments [ 0 ] === 'projects' && pathSegments [ 1 ] ) {
34+ projectName = pathSegments [ 1 ] ;
35+
36+ // Check if we're in a devlog path
37+ if ( pathSegments [ 2 ] === 'devlogs' && pathSegments [ 3 ] ) {
38+ const parsedDevlogId = parseInt ( pathSegments [ 3 ] , 10 ) ;
39+ if ( ! isNaN ( parsedDevlogId ) ) {
40+ devlogId = parsedDevlogId ;
41+ }
42+ }
43+ }
44+
2545 const { currentProjectContext, currentProjectName, projectsContext, fetchProjects } =
2646 useProjectStore ( ) ;
27- const { currentDevlogContext, currentDevlogId } = useDevlogStore ( ) ;
47+ const { currentDevlogContext } = useDevlogStore ( ) ;
2848
29- // Don't show breadcrumb on the home or project list page
30- if ( [ '/' , '/projects' ] . includes ( pathname ) ) {
49+ // If we are not in a project context, do not render the breadcrumb
50+ if ( ! projectName ) {
3151 return null ;
3252 }
3353
@@ -50,12 +70,15 @@ export function NavigationBreadcrumb() {
5070 }
5171 } ;
5272
53- const handleDropdownOpenChange = ( open : boolean ) => {
54- if ( open ) {
55- // Load projects when dropdown is opened
56- fetchProjects ( ) ;
57- }
58- } ;
73+ const dropdownSkeletons = Array . from ( { length : 3 } ) . map ( ( _ , index ) => (
74+ < DropdownMenuItem key = { index } disabled className = "flex items-center gap-3 p-3" >
75+ < Skeleton className = "w-6 h-6 rounded-full flex-shrink-0" />
76+ < div className = "flex-1 min-w-0 space-y-1" >
77+ < Skeleton className = "h-4 w-full" />
78+ < Skeleton className = "h-3 w-8" />
79+ </ div >
80+ </ DropdownMenuItem >
81+ ) ) ;
5982
6083 const renderProjectDropdown = ( ) => {
6184 // Show skeleton if current project is loading
@@ -68,29 +91,24 @@ export function NavigationBreadcrumb() {
6891 }
6992
7093 return (
71- < DropdownMenu onOpenChange = { handleDropdownOpenChange } >
94+ < DropdownMenu
95+ onOpenChange = { async ( open ) => {
96+ if ( open ) await fetchProjects ( ) ;
97+ } }
98+ >
7299 < DropdownMenuTrigger asChild >
73100 < div className = "flex items-center gap-2 cursor-pointer rounded" >
74101 < Package size = { 14 } />
75- < span > { currentProjectContext . data ?. name } </ span >
102+ < span > { projectName } </ span >
76103 < ChevronsUpDown size = { 14 } className = "text-muted-foreground" />
77104 </ div >
78105 </ DropdownMenuTrigger >
79106 < DropdownMenuContent align = "start" className = "w-64" >
80107 { /* Show skeleton items if projects list is loading */ }
81108 { projectsContext . loading
82- ? Array . from ( { length : 3 } ) . map ( ( _ , index ) => (
83- < DropdownMenuItem key = { index } disabled className = "flex items-center gap-3 p-3" >
84- < Skeleton className = "w-6 h-6 rounded-full flex-shrink-0" />
85- < div className = "flex-1 min-w-0 space-y-1" >
86- < Skeleton className = "h-4 w-full" />
87- < Skeleton className = "h-3 w-8" />
88- </ div >
89- </ DropdownMenuItem >
90- ) )
109+ ? dropdownSkeletons
91110 : projectsContext . data ?. map ( ( project ) => {
92- const isCurrentProject = currentProjectName === project . name ;
93-
111+ const isCurrentProject = projectName === project . name ;
94112 return (
95113 < DropdownMenuItem
96114 key = { project . id }
@@ -100,11 +118,11 @@ export function NavigationBreadcrumb() {
100118 >
101119 < div className = "flex-1 min-w-0" >
102120 < div className = "text-sm font-medium truncate" > { project . name } </ div >
103- < div className = "text-xs text-muted-foreground truncate" > { project . description } </ div >
121+ < div className = "text-xs text-muted-foreground truncate" >
122+ { project . description }
123+ </ div >
104124 </ div >
105- { isCurrentProject && (
106- < Check size = { 14 } className = "text-primary flex-shrink-0" />
107- ) }
125+ { isCurrentProject && < Check size = { 14 } className = "text-primary flex-shrink-0" /> }
108126 </ DropdownMenuItem >
109127 ) ;
110128 } ) }
@@ -134,8 +152,8 @@ export function NavigationBreadcrumb() {
134152 return (
135153 < Breadcrumb className = "navigation-breadcrumb" >
136154 < BreadcrumbList >
137- { currentProjectName && < BreadcrumbItem > { renderProjectDropdown ( ) } </ BreadcrumbItem > }
138- { currentDevlogId && (
155+ < BreadcrumbItem > { renderProjectDropdown ( ) } </ BreadcrumbItem >
156+ { devlogId && (
139157 < >
140158 < BreadcrumbSeparator />
141159 < BreadcrumbItem > { renderDevlogDropdown ( ) } </ BreadcrumbItem >
0 commit comments