feat: apply new api to entry column
This commit is contained in:
@@ -1,25 +1,26 @@
|
||||
import dayjs from "@renderer/lib/dayjs"
|
||||
import { SiteIcon } from "../site-icon"
|
||||
import { EntriesResponse } from "@renderer/lib/types"
|
||||
|
||||
export function ArticleItem({ entry }: { entry: any }) {
|
||||
export function ArticleItem({ entry }: { entry: EntriesResponse[number] }) {
|
||||
return (
|
||||
<div className="flex my-5 px-2 py-3">
|
||||
<SiteIcon url={entry.feed.site_url} />
|
||||
<SiteIcon url={entry.feeds.siteUrl} />
|
||||
<div className="line-clamp-5 text-sm flex-1 -mt-0.5 leading-tight">
|
||||
<div className="text-zinc-500 text-[10px] space-x-1">
|
||||
<span>{entry.feed.title}</span>
|
||||
<span>{entry.feeds.title}</span>
|
||||
<span>·</span>
|
||||
<span>
|
||||
{dayjs
|
||||
.duration(
|
||||
dayjs(entry.published_at).diff(dayjs(), "minute"),
|
||||
dayjs(entry.publishedAt).diff(dayjs(), "minute"),
|
||||
"minute",
|
||||
)
|
||||
.humanize()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="font-medium my-0.5">{entry.title}</div>
|
||||
<div className="text-zinc-500 text-[13px]">{entry.text}</div>
|
||||
<div className="text-zinc-500 text-[13px]">{entry.description}</div>
|
||||
</div>
|
||||
{entry.images?.[0] && (
|
||||
<img
|
||||
|
||||
@@ -8,7 +8,7 @@ import { PictureItem } from "./picture-item"
|
||||
import { VideoItem } from "./video-item"
|
||||
import { NotificationItem } from "./notification-item"
|
||||
|
||||
const gridMode = ["Pictures", "Videos"]
|
||||
const gridMode = [2, 3]
|
||||
|
||||
export function EntryColumn({
|
||||
activedList,
|
||||
@@ -25,20 +25,20 @@ export function EntryColumn({
|
||||
})
|
||||
|
||||
let Item
|
||||
switch (activedList?.type) {
|
||||
case "Articles":
|
||||
switch (activedList?.view) {
|
||||
case 0:
|
||||
Item = ArticleItem
|
||||
break
|
||||
case "Social Media":
|
||||
case 1:
|
||||
Item = SocialMediaItem
|
||||
break
|
||||
case "Pictures":
|
||||
case 2:
|
||||
Item = PictureItem
|
||||
break
|
||||
case "Videos":
|
||||
case 3:
|
||||
Item = VideoItem
|
||||
break
|
||||
case "Notifications":
|
||||
case 4:
|
||||
Item = NotificationItem
|
||||
break
|
||||
default:
|
||||
@@ -66,11 +66,12 @@ export function EntryColumn({
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
className={cn(
|
||||
gridMode.includes(activedList?.type || "") &&
|
||||
activedList?.view &&
|
||||
gridMode.includes(activedList.view) &&
|
||||
"grid gap-2 grid-cols-2 md:grid-cols-3 lg:grid-cols-4 px-2",
|
||||
)}
|
||||
>
|
||||
{page.entries.map((entry) => (
|
||||
{page.data?.map((entry) => (
|
||||
<div
|
||||
key={entry.id}
|
||||
className={cn(
|
||||
|
||||
@@ -31,7 +31,7 @@ export function FeedList({
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
setActivedList({
|
||||
level: levels.type,
|
||||
level: levels.view,
|
||||
id: view,
|
||||
name: views[view].name,
|
||||
view,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const levels = {
|
||||
type: "type",
|
||||
view: "view",
|
||||
folder: "folder",
|
||||
feed: "feed",
|
||||
entry: "entry",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useInfiniteQuery } from "@tanstack/react-query"
|
||||
import { parseHtml } from "./parse-html"
|
||||
import { levels } from "@renderer/lib/constants"
|
||||
import { EntriesResponse, ListResponse } from "./types"
|
||||
|
||||
export const useEntries = ({
|
||||
level,
|
||||
@@ -11,63 +11,46 @@ export const useEntries = ({
|
||||
}) =>
|
||||
useInfiniteQuery({
|
||||
queryKey: ["entries", level, id],
|
||||
enabled: !!level && !!id,
|
||||
enabled: level !== undefined && id !== undefined,
|
||||
queryFn: async ({ pageParam }) => {
|
||||
let entries
|
||||
let entries: ListResponse<EntriesResponse> | null = null
|
||||
if (level === levels.folder) {
|
||||
entries = await (
|
||||
await fetch(
|
||||
`${import.meta.env.VITE_MINIFLUX_ENDPOINT}/v1/entries?` +
|
||||
`${import.meta.env.VITE_ELECTRON_REMOTE_API_URL}/entries?` +
|
||||
new URLSearchParams({
|
||||
direction: "desc",
|
||||
limit: "20",
|
||||
after_entry_id: pageParam,
|
||||
category_id: id + "",
|
||||
offset: pageParam + "",
|
||||
category: id + "",
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
"X-Auth-Token": import.meta.env.VITE_MINIFLUX_TOKEN,
|
||||
},
|
||||
credentials: "include",
|
||||
},
|
||||
)
|
||||
).json()
|
||||
} else if (level === levels.type) {
|
||||
} else if (level === levels.view) {
|
||||
entries = await (
|
||||
await fetch(
|
||||
`${import.meta.env.VITE_MINIFLUX_ENDPOINT}/v1/entries?` +
|
||||
`${import.meta.env.VITE_ELECTRON_REMOTE_API_URL}/entries?` +
|
||||
new URLSearchParams({
|
||||
direction: "desc",
|
||||
limit: "20",
|
||||
after_entry_id: pageParam,
|
||||
offset: pageParam + "",
|
||||
view: id + "",
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
"X-Auth-Token": import.meta.env.VITE_MINIFLUX_TOKEN,
|
||||
},
|
||||
credentials: "include",
|
||||
},
|
||||
)
|
||||
).json()
|
||||
}
|
||||
entries.entries = await Promise.all(
|
||||
entries.entries.map(async (entry) => {
|
||||
entry.content = entry.content.replaceAll(
|
||||
"https://pixiv.diygod.me/",
|
||||
"https://i.pximg.net/",
|
||||
)
|
||||
const parsed = await parseHtml(entry.content)
|
||||
return {
|
||||
...entry,
|
||||
text: parsed.metadata?.desctription,
|
||||
images: parsed.metadata?.images,
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
if (!entries) {
|
||||
entries = {
|
||||
code: -1,
|
||||
}
|
||||
}
|
||||
|
||||
return entries
|
||||
},
|
||||
getNextPageParam: (lastPage) =>
|
||||
lastPage?.entries?.length
|
||||
? lastPage.entries[lastPage.entries.length - 1].id
|
||||
: "",
|
||||
initialPageParam: "",
|
||||
getNextPageParam: (lastPage, _, lastPageParam) =>
|
||||
lastPageParam + (lastPage.data?.length || 0),
|
||||
initialPageParam: 0,
|
||||
})
|
||||
|
||||
@@ -1,26 +1,5 @@
|
||||
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
|
||||
}
|
||||
}[]
|
||||
import { SubscriptionResponse } from "./types"
|
||||
|
||||
export type Response = {
|
||||
list: {
|
||||
|
||||
@@ -6,3 +6,57 @@ export type ActivedList = {
|
||||
} | null
|
||||
|
||||
export type ActivedEntry = Record<string, any> | null
|
||||
|
||||
type FeedResponse = {
|
||||
id: string
|
||||
url: string
|
||||
title: string
|
||||
description: string
|
||||
siteUrl: string
|
||||
image: string
|
||||
checkedAt: string
|
||||
nextCheckAt: string
|
||||
lastModifiedHeader: string
|
||||
etagHeader: string
|
||||
ttl: number
|
||||
}
|
||||
|
||||
export type SubscriptionResponse = {
|
||||
userId: string
|
||||
feedId: string
|
||||
view: number
|
||||
category: string
|
||||
title: string
|
||||
unread?: number
|
||||
feeds: FeedResponse
|
||||
}[]
|
||||
|
||||
export type EntriesResponse = {
|
||||
author?: string
|
||||
category?: string[]
|
||||
changedAt: string
|
||||
content?: string
|
||||
description?: string
|
||||
enclosure?: {
|
||||
url: string
|
||||
type?: string
|
||||
length?: number
|
||||
title?: string
|
||||
}
|
||||
feedId: string
|
||||
feeds: FeedResponse
|
||||
guid: string
|
||||
id: string
|
||||
images?: string[]
|
||||
publishedAt: string
|
||||
readingTime?: number
|
||||
title?: string
|
||||
url?: string
|
||||
}[]
|
||||
|
||||
export type ListResponse<T> = {
|
||||
code: number
|
||||
data?: T
|
||||
total?: number
|
||||
message?: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user