Skip to content

Commit

Permalink
feat: sort by unread
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Apr 13, 2024
1 parent df1bff6 commit 1da41f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/renderer/src/components/feed-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export function FeedList({ type }: { type: string }) {
<div className="font-bold">{type}</div>
<div className='text-sm text-zinc-500 ml-2'>{feeds.data?.unread}</div>
</div>
{Object.keys(feeds.data?.list || {}).map((category) => (
<FeedCategory key={category} name={category} data={feeds.data?.list[category]} />
{feeds.data?.list.map((category) => (
<FeedCategory key={category.name} data={category} />
))}
</div>
)
}

function FeedCategory({ name, data }: { name: string; data: any }) {
function FeedCategory({ data }: { data: any }) {
const [open, setOpen] = useState(false)

return (
Expand All @@ -30,7 +30,7 @@ function FeedCategory({ name, data }: { name: string; data: any }) {
<CollapsibleTrigger className="flex items-center justify-between font-medium text-sm leading-loose py-[2px] w-full [&_.i-mingcute-right-fill]:data-[state=open]:rotate-90">
<div className='flex items-center min-w-0'>
<i className="i-mingcute-right-fill mr-2 transition-transform" />
<span className='truncate'>{name}</span>
<span className='truncate'>{data.name}</span>
</div>
{!!data.unread && <div className='text-xs text-zinc-500 ml-2'>{data.unread}</div>}
</CollapsibleTrigger>
Expand All @@ -42,7 +42,6 @@ function FeedCategory({ name, data }: { name: string; data: any }) {
duration: 0.2,
ease: 'easeInOut',
}}
key={name}
className="overflow-hidden"
initial={{
height: 0,
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/src/lib/feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export const useFeeds = () =>
categories.list[feed.category.title].unread += unread
categories.unread += unread
})
return categories
const list = Object.entries(categories.list).map(([name, list]: any) => ({
name,
list: list.list.sort((a, b) => b.unread - a.unread),
unread: list.unread
})).sort((a, b) => b.unread - a.unread)
return {
list,
unread: categories.unread
}
}
})

0 comments on commit 1da41f7

Please sign in to comment.