Skip to content

Commit

Permalink
feat: sort by unread count
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban committed Aug 17, 2024
1 parent 96fb9bd commit 0b870de
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions components/feed-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,17 @@ export function FeedList({ view }: { view: TabViewIndex }) {
Object.entries(feedsGrouped),
([title, data]) => isSingleCategory(data)
? [data]
: [title, data],
).flat(),
: [
title,
data.sort((a, b) => b.unread - a.unread),
],
)
.sort((a, b) => {
const unreadA = Array.isArray(a[0]) ? a[0].reduce((acc, sub) => acc + sub.unread, 0) : Array.isArray(a[1]) ? a[1].reduce((acc, sub) => acc + sub.unread, 0) : 0
const unreadB = Array.isArray(b[0]) ? b[0].reduce((acc, sub) => acc + sub.unread, 0) : Array.isArray(b[1]) ? b[1].reduce((acc, sub) => acc + sub.unread, 0) : 0
return unreadB - unreadA
})
.flat(),
[feedsGrouped],
)

Expand Down

0 comments on commit 0b870de

Please sign in to comment.