Skip to content

Commit

Permalink
Don't filter and return the entire list.
Browse files Browse the repository at this point in the history
The counts will load once the API call is done.
  • Loading branch information
ramonjd committed Sep 12, 2024
1 parent 07c8388 commit 9f5b1e7
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ export function useDefaultViewsWithItemCounts( { postType } ) {
} );

return useMemo( () => {
if ( ! records || ! defaultViews ) {
if ( ! defaultViews ) {
return [];
}

if ( ! records ) {
return defaultViews;
}

const counts = {
all: totalItems,
drafts: records.filter( ( record ) => record.status === 'draft' )
Expand All @@ -98,14 +102,10 @@ export function useDefaultViewsWithItemCounts( { postType } ) {
};

// Filter out views with > 0 item counts.
return defaultViews
.map( ( _view ) => {
if ( counts?.[ _view.slug ] > 0 ) {
_view.count = counts[ _view.slug ];
}
return _view;
} )
.filter( ( view ) => !! view.count );
return defaultViews.map( ( _view ) => {
_view.count = counts[ _view.slug ];
return _view;
} );
}, [ defaultViews, records, totalItems ] );
}

Expand Down

0 comments on commit 9f5b1e7

Please sign in to comment.