@@ -307,6 +307,14 @@ const MainApp: React.FC = () => {
307307 return Number . isNaN ( date . getTime ( ) ) ? null : date ;
308308 } ;
309309
310+ const formatNodeTitle = ( node : DocumentOrFolder ) => {
311+ const trimmed = node . title . trim ( ) ;
312+ if ( trimmed ) {
313+ return trimmed ;
314+ }
315+ return node . type === 'folder' ? 'Untitled Folder' : 'Untitled Document' ;
316+ } ;
317+
310318 const computeFromTree = ( folderNode : DocumentNode ) : FolderOverviewMetrics => {
311319 const recordLatest = ( ( ) => {
312320 let latest : Date | null = null ;
@@ -325,25 +333,45 @@ const MainApp: React.FC = () => {
325333
326334 recordLatest . update ( folderNode . updatedAt ) ;
327335
328- const directDocumentCount = folderNode . children . filter ( child => child . type === 'document' ) . length ;
329- const directFolderCount = folderNode . children . filter ( child => child . type === 'folder' ) . length ;
336+ const folderChildren = folderNode . children ?? [ ] ;
337+ const directDocumentCount = folderChildren . filter ( child => child . type === 'document' ) . length ;
338+ const directFolderCount = folderChildren . filter ( child => child . type === 'folder' ) . length ;
330339
331340 let totalDocumentCount = 0 ;
332341 let totalFolderCount = 0 ;
333- const stack = [ ...folderNode . children ] ;
342+ const stack : { node : DocumentNode ; parentPath : string [ ] } [ ] = folderChildren . map ( child => ( {
343+ node : child ,
344+ parentPath : [ ] ,
345+ } ) ) ;
346+ const recentDocuments : FolderOverviewMetrics [ 'recentDocuments' ] = [ ] ;
334347
335348 while ( stack . length > 0 ) {
336- const current = stack . pop ( ) ! ;
349+ const { node : current , parentPath } = stack . pop ( ) ! ;
337350 recordLatest . update ( current . updatedAt ) ;
338351 if ( current . type === 'document' ) {
339352 totalDocumentCount += 1 ;
353+ recentDocuments . push ( {
354+ id : current . id ,
355+ title : current . title ,
356+ updatedAt : current . updatedAt ,
357+ parentPath,
358+ } ) ;
340359 } else if ( current . type === 'folder' ) {
341360 totalFolderCount += 1 ;
342- stack . push ( ...current . children ) ;
361+ const nextPath = [ ...parentPath , formatNodeTitle ( current ) ] ;
362+ const childNodes = current . children ?? [ ] ;
363+ stack . push ( ...childNodes . map ( child => ( { node : child , parentPath : nextPath } ) ) ) ;
343364 }
344365 }
345366
346367 const latestDate = recordLatest . getValue ( ) ;
368+ const sortedRecent = recentDocuments
369+ . sort ( ( a , b ) => {
370+ const aDate = parseDate ( a . updatedAt ) ?. getTime ( ) ?? 0 ;
371+ const bDate = parseDate ( b . updatedAt ) ?. getTime ( ) ?? 0 ;
372+ return bDate - aDate ;
373+ } )
374+ . slice ( 0 , 5 ) ;
347375
348376 return {
349377 directDocumentCount,
@@ -352,6 +380,7 @@ const MainApp: React.FC = () => {
352380 totalFolderCount,
353381 totalItemCount : totalDocumentCount + totalFolderCount ,
354382 lastUpdated : latestDate ? latestDate . toISOString ( ) : null ,
383+ recentDocuments : sortedRecent ,
355384 } ;
356385 } ;
357386
@@ -393,21 +422,39 @@ const MainApp: React.FC = () => {
393422
394423 let totalDocumentCount = 0 ;
395424 let totalFolderCount = 0 ;
396- const stack = [ ...directChildren ] ;
425+ const stack : { node : DocumentOrFolder ; parentPath : string [ ] } [ ] = directChildren . map ( child => ( {
426+ node : child ,
427+ parentPath : [ ] ,
428+ } ) ) ;
429+ const recentDocuments : FolderOverviewMetrics [ 'recentDocuments' ] = [ ] ;
397430
398431 while ( stack . length > 0 ) {
399- const current = stack . pop ( ) ! ;
432+ const { node : current , parentPath } = stack . pop ( ) ! ;
400433 recordLatest . update ( current . updatedAt ) ;
401434 if ( current . type === 'document' ) {
402435 totalDocumentCount += 1 ;
436+ recentDocuments . push ( {
437+ id : current . id ,
438+ title : current . title ,
439+ updatedAt : current . updatedAt ,
440+ parentPath,
441+ } ) ;
403442 } else {
404443 totalFolderCount += 1 ;
405444 const childItems = childMap . get ( current . id ) ?? [ ] ;
406- stack . push ( ...childItems ) ;
445+ const nextPath = [ ...parentPath , formatNodeTitle ( current ) ] ;
446+ stack . push ( ...childItems . map ( item => ( { node : item , parentPath : nextPath } ) ) ) ;
407447 }
408448 }
409449
410450 const latestDate = recordLatest . getValue ( ) ;
451+ const sortedRecent = recentDocuments
452+ . sort ( ( a , b ) => {
453+ const aDate = parseDate ( a . updatedAt ) ?. getTime ( ) ?? 0 ;
454+ const bDate = parseDate ( b . updatedAt ) ?. getTime ( ) ?? 0 ;
455+ return bDate - aDate ;
456+ } )
457+ . slice ( 0 , 5 ) ;
411458
412459 return {
413460 directDocumentCount,
@@ -416,6 +463,7 @@ const MainApp: React.FC = () => {
416463 totalFolderCount,
417464 totalItemCount : totalDocumentCount + totalFolderCount ,
418465 lastUpdated : latestDate ? latestDate . toISOString ( ) : null ,
466+ recentDocuments : sortedRecent ,
419467 } ;
420468 } ;
421469
@@ -1308,6 +1356,7 @@ const MainApp: React.FC = () => {
13081356 totalFolderCount : 0 ,
13091357 totalItemCount : 0 ,
13101358 lastUpdated : activeNode . updatedAt ,
1359+ recentDocuments : [ ] ,
13111360 } ;
13121361 return (
13131362 < FolderOverview
0 commit comments