feat: type filter

This commit is contained in:
DIYgod 2024-04-13 23:10:10 +08:00
parent cea06813b5
commit f04a74ec7f
No known key found for this signature in database
2 changed files with 25 additions and 14 deletions

View File

@ -15,7 +15,7 @@ export function FeedList({
activedList: ActivedList,
setActivedList: (value: ActivedList) => void
}) {
const feeds = useFeeds()
const feeds = useFeeds(type)
return (
<div className="w-64 px-3">
@ -69,7 +69,7 @@ function FeedCategory({
>
<div className={cn("flex items-center justify-between font-medium text-sm leading-loose px-2.5 py-[2px] rounded w-full [&_.i-mingcute-right-fill]:data-[state=open]:rotate-90 cursor-pointer", activedList?.level === levels.folder && activedList.id === data.id && 'bg-[#C9C9C7]')}>
<div className='flex items-center min-w-0'>
<CollapsibleTrigger className='flex items-center'>
<CollapsibleTrigger className='flex items-center h-7'>
<i className="i-mingcute-right-fill mr-2 transition-transform" />
</CollapsibleTrigger>
<span className='truncate'>{data.name}</span>

View File

@ -1,8 +1,17 @@
import { useQuery } from '@tanstack/react-query'
export const useFeeds = () =>
const typeMap = {
'Articles': ['Forum', 'News', 'Game', 'Shopping', 'Blog', 'Knowledge'],
'Social Media': ['Twitter', 'Weibo'],
'Pictures': ['Picture'],
'Videos': ['bilibili', 'YouTube', 'Video'],
'Audios': [],
'Notifications': ['Software'],
}
export const useFeeds = (type: string) =>
useQuery({
queryKey: ['feeds'],
queryKey: ['feeds', type],
queryFn: async () => {
const feeds = await (await fetch(`${import.meta.env.VITE_MINIFLUX_ENDPOINT}/v1/feeds`, {
headers: {
@ -20,18 +29,20 @@ export const useFeeds = () =>
unread: 0,
}
feeds?.forEach((feed) => {
if (!categories.list[feed.category.title]) {
categories.list[feed.category.title] = {
list: [],
unread: 0,
id: feed.category.id
if (typeMap[type].includes(feed.category.title)) {
if (!categories.list[feed.category.title]) {
categories.list[feed.category.title] = {
list: [],
unread: 0,
id: feed.category.id
}
}
const unread = counters.unreads[feed.id] || 0
feed.unread = unread
categories.list[feed.category.title].list.push(feed)
categories.list[feed.category.title].unread += unread
categories.unread += unread
}
const unread = counters.unreads[feed.id] || 0
feed.unread = unread
categories.list[feed.category.title].list.push(feed)
categories.list[feed.category.title].unread += unread
categories.unread += unread
})
const list = Object.entries(categories.list).map(([name, list]: any) => ({
name,