feat: new api for feed column
This commit is contained in:
@@ -12,42 +12,10 @@ import { m, useSpring } from "framer-motion"
|
||||
import { FeedList } from "./list"
|
||||
import { ActivedList } from "@renderer/lib/types"
|
||||
import { UserButton } from "@renderer/components/user-button"
|
||||
import { views } from "@renderer/lib/constants"
|
||||
|
||||
const lethargy = new Lethargy()
|
||||
|
||||
const items = [
|
||||
{
|
||||
name: "Articles",
|
||||
icon: <i className="i-mingcute-news-fill" />,
|
||||
className: "text-amber-700",
|
||||
},
|
||||
{
|
||||
name: "Social Media",
|
||||
icon: <i className="i-mingcute-twitter-fill" />,
|
||||
className: "text-sky-600",
|
||||
},
|
||||
{
|
||||
name: "Pictures",
|
||||
icon: <i className="i-mingcute-pic-fill" />,
|
||||
className: "text-green-600",
|
||||
},
|
||||
{
|
||||
name: "Videos",
|
||||
icon: <i className="i-mingcute-youtube-fill" />,
|
||||
className: "text-red-600",
|
||||
},
|
||||
{
|
||||
name: "Audios",
|
||||
icon: <i className="i-mingcute-headphone-fill" />,
|
||||
className: "text-purple-600",
|
||||
},
|
||||
{
|
||||
name: "Notifications",
|
||||
icon: <i className="i-mingcute-notification-fill" />,
|
||||
className: "text-yellow-600",
|
||||
},
|
||||
]
|
||||
|
||||
export function FeedColumn({
|
||||
activedList,
|
||||
setActivedList,
|
||||
@@ -73,7 +41,7 @@ export function FeedColumn({
|
||||
const s = lethargy.check(event)
|
||||
if (s) {
|
||||
if (!wait && Math.abs(dex) > 20) {
|
||||
setActive((i) => clamp(i + dx, 0, items.length - 1))
|
||||
setActive((i) => clamp(i + dx, 0, views.length - 1))
|
||||
return true
|
||||
} else {
|
||||
return undefined
|
||||
@@ -95,27 +63,27 @@ export function FeedColumn({
|
||||
className="h-full flex flex-col"
|
||||
onClick={() =>
|
||||
setActivedList({
|
||||
level: "type",
|
||||
id: items[active].name,
|
||||
name: items[active].name,
|
||||
type: items[active].name,
|
||||
level: "view",
|
||||
id: active,
|
||||
name: views[active].name,
|
||||
view: active,
|
||||
})
|
||||
}
|
||||
>
|
||||
<UserButton className="h-12 mx-3 mb-2 mt-1" />
|
||||
<div className="flex text-zinc-500 w-full justify-between text-xl my-2 px-5">
|
||||
<TooltipProvider delayDuration={300}>
|
||||
{items.map((item, index) => (
|
||||
{views.map((item, index) => (
|
||||
<div
|
||||
key={item.name}
|
||||
className={cn(active === index && "text-zinc-800")}
|
||||
onClick={(e) => {
|
||||
setActive(index)
|
||||
setActivedList({
|
||||
level: "type",
|
||||
id: items[index].name,
|
||||
name: items[index].name,
|
||||
type: items[index].name,
|
||||
level: "view",
|
||||
id: index,
|
||||
name: views[index].name,
|
||||
view: index,
|
||||
})
|
||||
e.stopPropagation()
|
||||
}}
|
||||
@@ -130,10 +98,10 @@ export function FeedColumn({
|
||||
</div>
|
||||
<div className="w-full h-full overflow-x-hidden" ref={carouselRef}>
|
||||
<m.div className="h-full flex" style={{ x: spring }}>
|
||||
{items.map((item) => (
|
||||
{views.map((item, index) => (
|
||||
<section key={item.name} className="snap-center shrink-0">
|
||||
<FeedList
|
||||
type={item.name}
|
||||
view={index}
|
||||
activedList={activedList}
|
||||
setActivedList={setActivedList}
|
||||
/>
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
import { useFeeds } from "@renderer/lib/feeds"
|
||||
import { useSubscriptions } from "@renderer/lib/subscriptions"
|
||||
import {
|
||||
Collapsible,
|
||||
CollapsibleTrigger,
|
||||
} from "@renderer/components/ui/collapsible"
|
||||
import { m, AnimatePresence } from "framer-motion"
|
||||
import { useState } from "react"
|
||||
import { levels } from "@renderer/lib/constants"
|
||||
import { levels, views } from "@renderer/lib/constants"
|
||||
import { ActivedList } from "@renderer/lib/types"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
import { SiteIcon } from "../site-icon"
|
||||
import { Response as SubscriptionsResponse } from "@renderer/lib/subscriptions"
|
||||
|
||||
export function FeedList({
|
||||
type,
|
||||
view,
|
||||
activedList,
|
||||
setActivedList,
|
||||
}: {
|
||||
type: string
|
||||
view: number
|
||||
activedList: ActivedList
|
||||
setActivedList: (value: ActivedList) => void
|
||||
}) {
|
||||
const feeds = useFeeds(type)
|
||||
const subscriptions = useSubscriptions(view)
|
||||
|
||||
return (
|
||||
<div className="w-64 px-3">
|
||||
@@ -31,22 +32,24 @@ export function FeedList({
|
||||
e.stopPropagation()
|
||||
setActivedList({
|
||||
level: levels.type,
|
||||
id: type,
|
||||
name: type,
|
||||
type,
|
||||
id: view,
|
||||
name: views[view].name,
|
||||
view,
|
||||
})
|
||||
}}
|
||||
>
|
||||
<div className="font-bold">{type}</div>
|
||||
<div className="text-sm text-zinc-500 ml-2">{feeds.data?.unread}</div>
|
||||
<div className="font-bold">{views[view].name}</div>
|
||||
<div className="text-sm text-zinc-500 ml-2">
|
||||
{subscriptions.data?.unread}
|
||||
</div>
|
||||
</div>
|
||||
{feeds.data?.list.map((category) => (
|
||||
{subscriptions.data?.list.map((category) => (
|
||||
<FeedCategory
|
||||
key={category.name}
|
||||
data={category}
|
||||
activedList={activedList}
|
||||
setActivedList={setActivedList}
|
||||
type={type}
|
||||
view={view}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -57,12 +60,12 @@ function FeedCategory({
|
||||
data,
|
||||
activedList,
|
||||
setActivedList,
|
||||
type,
|
||||
view,
|
||||
}: {
|
||||
data: any
|
||||
data: SubscriptionsResponse["list"][number]
|
||||
activedList: ActivedList
|
||||
setActivedList: (value: ActivedList) => void
|
||||
type: string
|
||||
view: number
|
||||
}) {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
@@ -74,9 +77,9 @@ function FeedCategory({
|
||||
e.stopPropagation()
|
||||
setActivedList({
|
||||
level: levels.folder,
|
||||
id: data.id,
|
||||
id: data.name,
|
||||
name: data.name,
|
||||
type,
|
||||
view,
|
||||
})
|
||||
}}
|
||||
>
|
||||
@@ -84,7 +87,7 @@ function FeedCategory({
|
||||
className={cn(
|
||||
"flex items-center justify-between font-medium text-sm leading-loose px-2.5 py-[2px] rounded w-full cursor-pointer",
|
||||
activedList?.level === levels.folder &&
|
||||
activedList.id === data.id &&
|
||||
activedList.id === data.name &&
|
||||
"bg-[#C9C9C7]",
|
||||
)}
|
||||
>
|
||||
@@ -122,26 +125,26 @@ function FeedCategory({
|
||||
>
|
||||
{data.list.map((feed) => (
|
||||
<div
|
||||
key={feed.id}
|
||||
key={feed.feedId}
|
||||
className={cn(
|
||||
"flex items-center justify-between text-sm font-medium leading-loose w-full pl-6 pr-2.5 py-[2px] rounded cursor-pointer",
|
||||
activedList?.level === levels.feed &&
|
||||
activedList.id === feed.id &&
|
||||
activedList.id === feed.feedId &&
|
||||
"bg-[#C9C9C7]",
|
||||
)}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
setActivedList({
|
||||
level: levels.feed,
|
||||
id: feed.id,
|
||||
name: feed.title,
|
||||
type,
|
||||
id: feed.feedId,
|
||||
name: feed.feeds.title,
|
||||
view,
|
||||
})
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center min-w-0">
|
||||
<SiteIcon url={feed.site_url} className="w-4 h-4" />
|
||||
<div className="truncate">{feed.title}</div>
|
||||
<SiteIcon url={feed.feeds.siteUrl} className="w-4 h-4" />
|
||||
<div className="truncate">{feed.feeds.title}</div>
|
||||
</div>
|
||||
{!!feed.unread && (
|
||||
<div className="text-xs text-zinc-500 ml-2">
|
||||
|
||||
@@ -7,9 +7,13 @@ export function SiteIcon({
|
||||
url: string
|
||||
className?: string
|
||||
}) {
|
||||
let host
|
||||
try {
|
||||
host = new URL(url).host
|
||||
} catch (error) {}
|
||||
return (
|
||||
<img
|
||||
src={`https://icons.duckduckgo.com/ip3/${new URL(url).host}.ico`}
|
||||
src={`https://icons.duckduckgo.com/ip3/${host}.ico`}
|
||||
className={cn("w-5 h-5 mr-2 rounded-sm shrink-0", className)}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
export const levels = {
|
||||
type: "type",
|
||||
folder: "folder",
|
||||
feed: "feed",
|
||||
entry: "entry",
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
export const levels = {
|
||||
type: "type",
|
||||
folder: "folder",
|
||||
feed: "feed",
|
||||
entry: "entry",
|
||||
}
|
||||
|
||||
export const views = [
|
||||
{
|
||||
name: "Articles",
|
||||
icon: <i className="i-mingcute-news-fill" />,
|
||||
className: "text-amber-700",
|
||||
},
|
||||
{
|
||||
name: "Social Media",
|
||||
icon: <i className="i-mingcute-twitter-fill" />,
|
||||
className: "text-sky-600",
|
||||
},
|
||||
{
|
||||
name: "Pictures",
|
||||
icon: <i className="i-mingcute-pic-fill" />,
|
||||
className: "text-green-600",
|
||||
},
|
||||
{
|
||||
name: "Videos",
|
||||
icon: <i className="i-mingcute-youtube-fill" />,
|
||||
className: "text-red-600",
|
||||
},
|
||||
{
|
||||
name: "Audios",
|
||||
icon: <i className="i-mingcute-headphone-fill" />,
|
||||
className: "text-purple-600",
|
||||
},
|
||||
{
|
||||
name: "Notifications",
|
||||
icon: <i className="i-mingcute-notification-fill" />,
|
||||
className: "text-yellow-600",
|
||||
},
|
||||
]
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useInfiniteQuery } from "@tanstack/react-query"
|
||||
import { parseHtml } from "./parse-html"
|
||||
import { typeMap } from "./feeds"
|
||||
import { levels } from "@renderer/lib/constants"
|
||||
|
||||
export const useEntries = ({
|
||||
@@ -40,7 +39,6 @@ export const useEntries = ({
|
||||
direction: "desc",
|
||||
limit: "20",
|
||||
after_entry_id: pageParam,
|
||||
category_id: typeMap[id as string][0] + "",
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
|
||||
// const typeMap = {
|
||||
// 'Articles': ['Forum', 'News', 'Game', 'Shopping', 'Blog', 'Knowledge'],
|
||||
// 'Social Media': ['Twitter', 'Weibo'],
|
||||
// 'Pictures': ['Picture'],
|
||||
// 'Videos': ['bilibili', 'YouTube', 'Video'],
|
||||
// 'Audios': [],
|
||||
// 'Notifications': ['Software'],
|
||||
// }
|
||||
|
||||
export const typeMap = {
|
||||
Articles: [5, 6, 11, 12, 10, 15],
|
||||
"Social Media": [2, 9],
|
||||
Pictures: [7],
|
||||
Videos: [3, 4, 8],
|
||||
Audios: [],
|
||||
Notifications: [13],
|
||||
}
|
||||
|
||||
export const useFeeds = (type: string) =>
|
||||
useQuery({
|
||||
queryKey: ["feeds", type],
|
||||
queryFn: async () => {
|
||||
const feeds = await (
|
||||
await fetch(`${import.meta.env.VITE_MINIFLUX_ENDPOINT}/v1/feeds`, {
|
||||
headers: {
|
||||
"X-Auth-Token": import.meta.env.VITE_MINIFLUX_TOKEN,
|
||||
},
|
||||
})
|
||||
).json()
|
||||
const counters = await (
|
||||
await fetch(
|
||||
`${import.meta.env.VITE_MINIFLUX_ENDPOINT}/v1/feeds/counters`,
|
||||
{
|
||||
headers: {
|
||||
"X-Auth-Token": import.meta.env.VITE_MINIFLUX_TOKEN,
|
||||
},
|
||||
},
|
||||
)
|
||||
).json()
|
||||
|
||||
const categories = {
|
||||
list: {},
|
||||
unread: 0,
|
||||
}
|
||||
feeds?.forEach((feed) => {
|
||||
if (typeMap[type].includes(feed.category.id)) {
|
||||
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 list = Object.entries(categories.list)
|
||||
.map(([name, list]: any) => ({
|
||||
name,
|
||||
list: list.list.sort((a, b) => b.unread - a.unread),
|
||||
unread: list.unread,
|
||||
id: list.id,
|
||||
}))
|
||||
.sort((a, b) => b.unread - a.unread)
|
||||
return {
|
||||
list,
|
||||
unread: categories.unread,
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,98 @@
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
|
||||
type SubscriptionResponse = {
|
||||
userId: string
|
||||
feedId: string
|
||||
view: number
|
||||
category: string
|
||||
title: string
|
||||
unread?: number
|
||||
feeds: {
|
||||
id: string
|
||||
url: string
|
||||
title: string
|
||||
description: string
|
||||
siteUrl: string
|
||||
image: string
|
||||
checkedAt: string
|
||||
nextCheckAt: string
|
||||
lastModifiedHeader: string
|
||||
etagHeader: string
|
||||
ttl: number
|
||||
}
|
||||
}[]
|
||||
|
||||
export type Response = {
|
||||
list: {
|
||||
list: SubscriptionResponse
|
||||
unread: number
|
||||
name: string
|
||||
}[]
|
||||
unread: number
|
||||
}
|
||||
|
||||
export const useSubscriptions = (view: number) =>
|
||||
useQuery({
|
||||
queryKey: ["subscriptions", view],
|
||||
queryFn: async () => {
|
||||
const subscriptions = (
|
||||
await (
|
||||
await fetch(
|
||||
`${import.meta.env.VITE_ELECTRON_REMOTE_API_URL}/subscriptions?view=${view}`,
|
||||
{
|
||||
credentials: "include",
|
||||
},
|
||||
)
|
||||
).json()
|
||||
).data as SubscriptionResponse
|
||||
// const counters = await (
|
||||
// await fetch(
|
||||
// `${import.meta.env.VITE_MINIFLUX_ENDPOINT}/v1/feeds/counters`,
|
||||
// {
|
||||
// headers: {
|
||||
// "X-Auth-Token": import.meta.env.VITE_MINIFLUX_TOKEN,
|
||||
// },
|
||||
// },
|
||||
// )
|
||||
// ).json()
|
||||
|
||||
const categories = {
|
||||
list: {},
|
||||
unread: 0,
|
||||
} as {
|
||||
list: Record<
|
||||
string,
|
||||
{
|
||||
list: SubscriptionResponse
|
||||
unread: number
|
||||
}
|
||||
>
|
||||
unread: number
|
||||
}
|
||||
subscriptions?.forEach((subscription) => {
|
||||
if (!categories.list[subscription.category]) {
|
||||
categories.list[subscription.category] = {
|
||||
list: [],
|
||||
unread: 0,
|
||||
}
|
||||
}
|
||||
// const unread = counters.unreads[feed.id] || 0
|
||||
const unread = 0
|
||||
subscription.unread = unread
|
||||
categories.list[subscription.category].list.push(subscription)
|
||||
categories.list[subscription.category].unread += unread
|
||||
categories.unread += unread
|
||||
})
|
||||
const list = Object.entries(categories.list)
|
||||
.map(([name, list]) => ({
|
||||
name,
|
||||
list: list.list.sort((a, b) => (b.unread || 0) - (a.unread || 0)),
|
||||
unread: list.unread,
|
||||
}))
|
||||
.sort((a, b) => b.unread - a.unread)
|
||||
return {
|
||||
list,
|
||||
unread: categories.unread,
|
||||
} as Response
|
||||
},
|
||||
})
|
||||
@@ -2,7 +2,7 @@ export type ActivedList = {
|
||||
level: string
|
||||
id: string | number
|
||||
name: string
|
||||
type: string
|
||||
view: number
|
||||
} | null
|
||||
|
||||
export type ActivedEntry = Record<string, any> | null
|
||||
|
||||
@@ -5,14 +5,14 @@ import { ActivedList, ActivedEntry } from "@renderer/lib/types"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
import { EntryContent } from "@renderer/components/entry-content"
|
||||
|
||||
const wideMode = ["Social Media", "Pictures", "Videos", "Audios"]
|
||||
const wideMode = [1, 2, 3, 4]
|
||||
|
||||
export function Component() {
|
||||
const [activedList, setActivedList] = useState<ActivedList>({
|
||||
level: "type",
|
||||
id: "Articles",
|
||||
level: "view",
|
||||
id: 0,
|
||||
name: "Articles",
|
||||
type: "Articles",
|
||||
view: 0,
|
||||
})
|
||||
const [activedEntry, setActivedEntry] = useState<ActivedEntry>(null)
|
||||
|
||||
@@ -24,7 +24,9 @@ export function Component() {
|
||||
<div
|
||||
className={cn(
|
||||
"pt-10 border-r shrink-0 h-full overflow-y-auto",
|
||||
wideMode.includes(activedList?.type || "") ? "flex-1" : "w-[340px]",
|
||||
activedList && wideMode.includes(activedList.view)
|
||||
? "flex-1"
|
||||
: "w-[340px]",
|
||||
)}
|
||||
>
|
||||
<EntryColumn
|
||||
@@ -33,7 +35,7 @@ export function Component() {
|
||||
setActivedEntry={setActivedEntry}
|
||||
/>
|
||||
</div>
|
||||
{!wideMode.includes(activedList?.type || "") && (
|
||||
{!(activedList && wideMode.includes(activedList.view)) && (
|
||||
<div className="flex-1 pt-10">
|
||||
<EntryContent entry={activedEntry} />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user