@@ -131,60 +131,30 @@ export default function FoldersScreen() {
131131 if ( ! isRefresh ) {
132132 setLoading ( true ) ;
133133 }
134- const [ foldersData , allNotes ] = await Promise . all ( [
134+
135+ // Fetch folders and counts in parallel (optimized - no note data fetched)
136+ const [ foldersData , noteCounts ] = await Promise . all ( [
135137 api . getFolders ( ) ,
136- api . getNotes ( ) // Get all notes to calculate accurate counts
138+ api . getNoteCounts ( )
137139 ] ) ;
138140
139141 if ( __DEV__ ) {
140- console . log ( `${ isRefresh ? 'Refresh' : 'Initial' } load - Total notes: ${ allNotes . length } ` ) ;
142+ console . log ( `${ isRefresh ? 'Refresh' : 'Initial' } load - Note counts:` , noteCounts ) ;
141143 }
142144
143145 // Show only ROOT folders (no parentId) on main screen
144- const rootFolders = foldersData . filter ( folder => ! folder . parentId ) ;
145-
146- // Calculate note counts for each root folder including subfolders
147- const getFolderAndSubfolderIds = ( folderId : string ) : string [ ] => {
148- const ids = [ folderId ] ;
149- const subfolders = foldersData . filter ( f => f . parentId === folderId ) ;
150- subfolders . forEach ( subfolder => {
151- ids . push ( ...getFolderAndSubfolderIds ( subfolder . id ) ) ;
152- } ) ;
153- return ids ;
154- } ;
155-
156- // Add note counts to root folders (including subfolder notes)
157- const rootFoldersWithCounts = rootFolders . map ( folder => {
158- const allFolderIds = getFolderAndSubfolderIds ( folder . id ) ;
159- const folderNotes = allNotes . filter ( note =>
160- allFolderIds . includes ( note . folderId || '' ) &&
161- ! note . deleted
162- ) ;
163- return {
164- ...folder ,
165- noteCount : folderNotes . length
166- } ;
167- } ) ;
168-
169- setAllFolders ( rootFoldersWithCounts ) ;
170-
171- // Calculate accurate counts from all notes - using web app field names
172- const trashedNotes = allNotes . filter ( note => note . deleted ) ;
173- const archivedNotes = allNotes . filter ( note => note . archived && ! note . deleted ) ;
174- const starredNotes = allNotes . filter ( note => note . starred && ! note . deleted && ! note . archived ) ;
175- const activeNotes = allNotes . filter ( note => ! note . deleted && ! note . archived ) ;
176-
177- const newCounts = {
178- all : activeNotes . length ,
179- starred : starredNotes . length ,
180- archived : archivedNotes . length ,
181- trash : trashedNotes . length ,
182- } ;
146+ // Note: For now, we don't show per-folder counts on home screen
147+ // Could be added later with a separate API endpoint
148+ const rootFolders = foldersData
149+ . filter ( folder => ! folder . parentId )
150+ . map ( folder => ( { ...folder , noteCount : 0 } ) ) ;
151+
152+ setAllFolders ( rootFolders ) ;
153+ setCounts ( noteCounts ) ;
183154
184155 if ( __DEV__ ) {
185- console . log ( 'Updated note counts:' , newCounts , 'Total notes loaded:' , allNotes . length ) ;
156+ console . log ( 'Updated note counts:' , noteCounts ) ;
186157 }
187- setCounts ( newCounts ) ;
188158 } catch ( error ) {
189159 if ( __DEV__ ) console . error ( 'Failed to load folders data:' , error ) ;
190160 setAllFolders ( [ ] ) ;
0 commit comments