@@ -6,7 +6,7 @@ import { GlobalFonts } from "./styles/fonts";
66import { GlobalScrollbars } from "./styles/scrollbars" ;
77import type { ProjectConfig } from "./config" ;
88import type { WorkspaceSelection } from "./components/ProjectSidebar" ;
9- import type { WorkspaceMetadataWithPaths } from "./types/workspace" ;
9+ import type { FrontendWorkspaceMetadata } from "./types/workspace" ;
1010import { LeftSidebar } from "./components/LeftSidebar" ;
1111import NewWorkspaceModal from "./components/NewWorkspaceModal" ;
1212import { AIView } from "./components/AIView" ;
@@ -173,17 +173,6 @@ function AppInner() {
173173 onSelectedWorkspaceUpdate : setSelectedWorkspace ,
174174 } ) ;
175175
176- // Build path-to-metadata lookup map (handles both stable and legacy paths)
177- const pathToMetadata = useMemo ( ( ) => {
178- const map = new Map < string , WorkspaceMetadataWithPaths > ( ) ;
179- for ( const metadata of workspaceMetadata . values ( ) ) {
180- // Map both stable path (with ID) and named path (with name/legacy)
181- map . set ( metadata . stableWorkspacePath , metadata ) ;
182- map . set ( metadata . namedWorkspacePath , metadata ) ;
183- }
184- return map ;
185- } , [ workspaceMetadata ] ) ;
186-
187176 // NEW: Sync workspace metadata with the stores
188177 const workspaceStore = useWorkspaceStoreRaw ( ) ;
189178 const gitStatusStore = useGitStatusStoreRaw ( ) ;
@@ -342,25 +331,32 @@ function AppInner() {
342331 const workspaceRecency = useWorkspaceRecency ( ) ;
343332
344333 // Sort workspaces by recency (most recent first)
334+ // Returns Map<projectPath, FrontendWorkspaceMetadata[]> for direct component use
345335 // Use stable reference to prevent sidebar re-renders when sort order hasn't changed
346336 const sortedWorkspacesByProject = useStableReference (
347337 ( ) => {
348- const result = new Map < string , ProjectConfig [ "workspaces" ] > ( ) ;
338+ // Build path-to-metadata lookup map internally
339+ const pathToMetadata = new Map < string , FrontendWorkspaceMetadata > ( ) ;
340+ for ( const metadata of workspaceMetadata . values ( ) ) {
341+ pathToMetadata . set ( metadata . stableWorkspacePath , metadata ) ;
342+ pathToMetadata . set ( metadata . namedWorkspacePath , metadata ) ;
343+ }
344+
345+ const result = new Map < string , FrontendWorkspaceMetadata [ ] > ( ) ;
349346 for ( const [ projectPath , config ] of projects ) {
350- result . set (
351- projectPath ,
352- config . workspaces . slice ( ) . sort ( ( a , b ) => {
353- // Look up metadata by workspace path (handles both stable and legacy paths)
354- const aMeta = pathToMetadata . get ( a . path ) ;
355- const bMeta = pathToMetadata . get ( b . path ) ;
356- if ( ! aMeta || ! bMeta ) return 0 ;
357-
358- // Get timestamp of most recent user message (0 if never used)
359- const aTimestamp = workspaceRecency [ aMeta . id ] ?? 0 ;
360- const bTimestamp = workspaceRecency [ bMeta . id ] ?? 0 ;
361- return bTimestamp - aTimestamp ;
362- } )
363- ) ;
347+ // Transform Workspace[] to FrontendWorkspaceMetadata[] and filter nulls
348+ const metadataList = config . workspaces
349+ . map ( ( ws ) => pathToMetadata . get ( ws . path ) )
350+ . filter ( ( meta ) : meta is FrontendWorkspaceMetadata => meta !== undefined ) ;
351+
352+ // Sort by recency
353+ metadataList . sort ( ( a , b ) => {
354+ const aTimestamp = workspaceRecency [ a . id ] ?? 0 ;
355+ const bTimestamp = workspaceRecency [ b . id ] ?? 0 ;
356+ return bTimestamp - aTimestamp ;
357+ } ) ;
358+
359+ result . set ( projectPath , metadataList ) ;
364360 }
365361 return result ;
366362 } ,
@@ -369,14 +365,14 @@ function AppInner() {
369365 if (
370366 ! compareMaps ( prev , next , ( a , b ) => {
371367 if ( a . length !== b . length ) return false ;
372- return a . every ( ( workspace , i ) => workspace . path === b [ i ] . path ) ;
368+ return a . every ( ( metadata , i ) => metadata . id === b [ i ] . id ) ;
373369 } )
374370 ) {
375371 return false ;
376372 }
377373 return true ;
378374 } ,
379- [ projects , workspaceMetadata , workspaceRecency , pathToMetadata ]
375+ [ projects , workspaceMetadata , workspaceRecency ]
380376 ) ;
381377
382378 const handleNavigateWorkspace = useCallback (
@@ -389,7 +385,7 @@ function AppInner() {
389385
390386 // Find current workspace index in sorted list
391387 const currentIndex = sortedWorkspaces . findIndex (
392- ( ws ) => ws . path === selectedWorkspace . workspacePath
388+ ( metadata ) => metadata . id === selectedWorkspace . workspaceId
393389 ) ;
394390 if ( currentIndex === - 1 ) return ;
395391
@@ -401,21 +397,17 @@ function AppInner() {
401397 targetIndex = currentIndex === 0 ? sortedWorkspaces . length - 1 : currentIndex - 1 ;
402398 }
403399
404- const targetWorkspace = sortedWorkspaces [ targetIndex ] ;
405- if ( ! targetWorkspace ) return ;
406-
407- // Look up metadata by workspace path (handles both stable and legacy paths)
408- const metadata = pathToMetadata . get ( targetWorkspace . path ) ;
409- if ( ! metadata ) return ;
400+ const targetMetadata = sortedWorkspaces [ targetIndex ] ;
401+ if ( ! targetMetadata ) return ;
410402
411403 setSelectedWorkspace ( {
412404 projectPath : selectedWorkspace . projectPath ,
413405 projectName : selectedWorkspace . projectName ,
414- workspacePath : targetWorkspace . path ,
415- workspaceId : metadata . id ,
406+ workspacePath : targetMetadata . stableWorkspacePath ,
407+ workspaceId : targetMetadata . id ,
416408 } ) ;
417409 } ,
418- [ selectedWorkspace , sortedWorkspacesByProject , pathToMetadata , setSelectedWorkspace ]
410+ [ selectedWorkspace , sortedWorkspacesByProject , setSelectedWorkspace ]
419411 ) ;
420412
421413 // Register command sources with registry
0 commit comments