diff --git a/src/renderer/src/components/entry-column/article-item.tsx b/src/renderer/src/components/entry-column/article-item.tsx index a71815305..f0ca7ae15 100644 --- a/src/renderer/src/components/entry-column/article-item.tsx +++ b/src/renderer/src/components/entry-column/article-item.tsx @@ -1,10 +1,10 @@ import { FeedIcon } from "@renderer/components/feed-icon" import { Image } from "@renderer/components/ui/image" import dayjs from "@renderer/lib/dayjs" -import type { EntriesResponse } from "@renderer/lib/types" +import type { TimelineResponse } from "@renderer/lib/types" import { cn } from "@renderer/lib/utils" -export function ArticleItem({ entry }: { entry: EntriesResponse[number] }) { +export function ArticleItem({ entry }: { entry: TimelineResponse[number] }) { return (
@@ -15,7 +15,7 @@ export function ArticleItem({ entry }: { entry: EntriesResponse[number] }) { {dayjs .duration( - dayjs(entry.publishedAt).diff(dayjs(), "minute"), + dayjs(entry.entries.publishedAt).diff(dayjs(), "minute"), "minute", ) .humanize()} @@ -28,13 +28,13 @@ export function ArticleItem({ entry }: { entry: EntriesResponse[number] }) { entry.read ? "text-zinc-500" : "text-black dark:text-white/90", )} > - {entry.title} + {entry.entries.title}
-
{entry.description}
+
{entry.entries.description}
- {entry.images?.[0] && ( + {entry.entries.images?.[0] && ( {page.data?.map((entry) => ( diff --git a/src/renderer/src/components/entry-column/item-wrapper.tsx b/src/renderer/src/components/entry-column/item-wrapper.tsx index a9b8fa49d..d2ad06d8a 100644 --- a/src/renderer/src/components/entry-column/item-wrapper.tsx +++ b/src/renderer/src/components/entry-column/item-wrapper.tsx @@ -1,7 +1,7 @@ import { useEntryActions } from "@renderer/hooks/useEntryActions" import { useUpdateEntry } from "@renderer/hooks/useUpdateEntry" import { showNativeMenu } from "@renderer/lib/native-menu" -import type { EntriesResponse } from "@renderer/lib/types" +import type { EntryResponse, TimelineResponse } from "@renderer/lib/types" import { cn } from "@renderer/lib/utils" import { apiFetch } from "@renderer/queries/api-fetch" import { feedActions, useFeedStore } from "@renderer/store" @@ -14,7 +14,7 @@ export function EntryItemWrapper({ children, view, }: { - entry: EntriesResponse[number] + entry: TimelineResponse[number] | EntryResponse children: React.ReactNode view?: number }) { @@ -28,7 +28,7 @@ export function EntryItemWrapper({ ) const updateEntry = useUpdateEntry({ - entryId: entry?.id, + entryId: entry?.entries.id, }) const read = useMutation({ @@ -36,7 +36,7 @@ export function EntryItemWrapper({ apiFetch("/reads", { method: "POST", body: { - entryId: entry?.id, + entryId: entry?.entries.id, }, }), onSuccess: () => { @@ -55,22 +55,22 @@ export function EntryItemWrapper({ target: itemRef, }) - if (!entry?.url || view === undefined) return children + if (!entry?.entries.url || view === undefined) return children return (
{ e.stopPropagation() - feedActions.setActiveEntry(entry.id) + feedActions.setActiveEntry(entry.entries.id) }} - onDoubleClick={() => entry.url && window.open(entry.url, "_blank")} + onDoubleClick={() => entry.entries.url && window.open(entry.entries.url, "_blank")} onContextMenu={(e) => { e.preventDefault() showNativeMenu( diff --git a/src/renderer/src/components/entry-column/notification-item.tsx b/src/renderer/src/components/entry-column/notification-item.tsx index 88b6f3d34..1797b5666 100644 --- a/src/renderer/src/components/entry-column/notification-item.tsx +++ b/src/renderer/src/components/entry-column/notification-item.tsx @@ -1,11 +1,11 @@ import { FeedIcon } from "@renderer/components/feed-icon" import dayjs from "@renderer/lib/dayjs" -import type { EntriesResponse } from "@renderer/lib/types" +import type { TimelineResponse } from "@renderer/lib/types" export function NotificationItem({ entry, }: { - entry: EntriesResponse[number] + entry: TimelineResponse[number] }) { return (
@@ -17,13 +17,13 @@ export function NotificationItem({ {dayjs .duration( - dayjs(entry.publishedAt).diff(dayjs(), "minute"), + dayjs(entry.entries.publishedAt).diff(dayjs(), "minute"), "minute", ) .humanize()}
-
{entry.title}
+
{entry.entries.title}
) diff --git a/src/renderer/src/components/entry-column/picture-item.tsx b/src/renderer/src/components/entry-column/picture-item.tsx index a360bb154..8311ace3f 100644 --- a/src/renderer/src/components/entry-column/picture-item.tsx +++ b/src/renderer/src/components/entry-column/picture-item.tsx @@ -1,14 +1,14 @@ import { FeedIcon } from "@renderer/components/feed-icon" import { Image } from "@renderer/components/ui/image" import dayjs from "@renderer/lib/dayjs" -import type { EntriesResponse } from "@renderer/lib/types" +import type { TimelineResponse } from "@renderer/lib/types" -export function PictureItem({ entry }: { entry: EntriesResponse[number] }) { +export function PictureItem({ entry }: { entry: TimelineResponse[number] }) { return (
- {entry.images?.slice(0, 1).map((image) => ( + {entry.entries.images?.slice(0, 1).map((image) => (
-
{entry.title}
+
{entry.entries.title}
{dayjs .duration( - dayjs(entry.publishedAt).diff(dayjs(), "minute"), + dayjs(entry.entries.publishedAt).diff(dayjs(), "minute"), "minute", ) .humanize()} diff --git a/src/renderer/src/components/entry-column/social-media-item.tsx b/src/renderer/src/components/entry-column/social-media-item.tsx index 3e67ef57f..c9f188feb 100644 --- a/src/renderer/src/components/entry-column/social-media-item.tsx +++ b/src/renderer/src/components/entry-column/social-media-item.tsx @@ -1,30 +1,30 @@ import { FeedIcon } from "@renderer/components/feed-icon" import { Image } from "@renderer/components/ui/image" import dayjs from "@renderer/lib/dayjs" -import type { EntriesResponse } from "@renderer/lib/types" +import type { TimelineResponse } from "@renderer/lib/types" -export function SocialMediaItem({ entry }: { entry: EntriesResponse[number] }) { +export function SocialMediaItem({ entry }: { entry: TimelineResponse[number] }) { return (
- {entry.author} + {entry.entries.author} · {dayjs .duration( - dayjs(entry.publishedAt).diff(dayjs(), "minute"), + dayjs(entry.entries.publishedAt).diff(dayjs(), "minute"), "minute", ) .humanize()}
-
{entry.description}
+
{entry.entries.description}
- {entry.images?.map((image) => ( + {entry.entries.images?.map((image) => (
-
{entry.title}
+
{entry.entries.title}
- {entry.author} + {entry.entries.author} · {dayjs .duration( - dayjs(entry.publishedAt).diff(dayjs(), "minute"), + dayjs(entry.entries.publishedAt).diff(dayjs(), "minute"), "minute", ) .humanize()} diff --git a/src/renderer/src/components/entry-content/index.tsx b/src/renderer/src/components/entry-content/index.tsx index 885aee0f8..f27e8487f 100644 --- a/src/renderer/src/components/entry-content/index.tsx +++ b/src/renderer/src/components/entry-content/index.tsx @@ -13,14 +13,14 @@ export function EntryContent({ entryId }: { entryId: ActiveEntry }) { const [content, setContent] = useState() useEffect(() => { - if (entry.data?.content) { - parseHtml(entry.data?.content).then((parsed) => { + if (entry.data?.entries.content) { + parseHtml(entry.data?.entries.content).then((parsed) => { setContent(parsed.content) }) } else { setContent(undefined) } - }, [entry.data?.content]) + }, [entry.data?.entries.content]) if (!entry.data) return null @@ -32,24 +32,24 @@ export function EntryContent({ entryId }: { entryId: ActiveEntry }) { initial={{ opacity: 0.01, y: 100 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0.01, y: -100 }} - key={entry.data?.id} + key={entry.data?.entries.id} >
- {entry.data?.title} + {entry.data?.entries.title}
{entry.data?.feeds?.title}
- {entry.data?.publishedAt && - new Date(entry.data?.publishedAt).toUTCString()} + {entry.data?.entries.publishedAt && + new Date(entry.data?.entries.publishedAt).toUTCString()}
diff --git a/src/renderer/src/components/entry-content/share.tsx b/src/renderer/src/components/entry-content/share.tsx index d6643bd23..036d8b4d9 100644 --- a/src/renderer/src/components/entry-content/share.tsx +++ b/src/renderer/src/components/entry-content/share.tsx @@ -6,20 +6,20 @@ import { TooltipTrigger, } from "@renderer/components/ui/tooltip" import { useEntryActions } from "@renderer/hooks/useEntryActions" -import type { EntriesResponse } from "@renderer/lib/types" +import type { EntryResponse } from "@renderer/lib/types" export function EntryShare({ view, entry, }: { view: number - entry?: EntriesResponse[number] + entry?: EntryResponse }) { const { items } = useEntryActions({ view, entry, }) - if (!entry?.url) return null + if (!entry?.entries.url) return null return (
diff --git a/src/renderer/src/components/follow/form.tsx b/src/renderer/src/components/follow/form.tsx index ba9dcfde4..0e97fb85c 100644 --- a/src/renderer/src/components/follow/form.tsx +++ b/src/renderer/src/components/follow/form.tsx @@ -16,7 +16,7 @@ import { } from "@renderer/components/ui/form" import { Image } from "@renderer/components/ui/image" import { Input } from "@renderer/components/ui/input" -import type { EntriesResponse, FeedResponse } from "@renderer/lib/types" +import type { FeedResponse } from "@renderer/lib/types" import { apiFetch } from "@renderer/queries/api-fetch" import { useMutation } from "@tanstack/react-query" import { useEffect } from "react" @@ -67,7 +67,7 @@ export function FollowForm({ type }: { type: string }) { data: { feed: FeedResponse docs?: string - entries?: Partial + entries?: Partial isSubscribed?: boolean subscriptionCount?: number }[] diff --git a/src/renderer/src/hono.ts b/src/renderer/src/hono.ts index 76095499b..a6f483196 100644 --- a/src/renderer/src/hono.ts +++ b/src/renderer/src/hono.ts @@ -3,6 +3,60 @@ import * as hono_utils_http_status from 'hono/utils/http-status'; import * as hono from 'hono'; declare const routes: hono_hono_base.HonoBase { const checkEagle = useQuery({ queryKey: ["check-eagle"], - enabled: !!entry?.url && !!view, + enabled: !!entry?.entries.url && !!view, queryFn: async () => { try { await ofetch("http://localhost:41595") @@ -31,7 +31,7 @@ export const useEntryActions = ({ }) const updateEntry = useUpdateEntry({ - entryId: entry?.id, + entryId: entry?.entries.id, }) const collect = useMutation({ @@ -39,12 +39,14 @@ export const useEntryActions = ({ apiFetch("/collections", { method: "POST", body: { - entryId: entry?.id, + entryId: entry?.entries.id, }, }), onSuccess: () => { updateEntry({ - collected: true, + collections: { + createdAt: new Date().toISOString(), + }, }) toast({ @@ -58,12 +60,12 @@ export const useEntryActions = ({ apiFetch("/collections", { method: "DELETE", body: { - entryId: entry?.id, + entryId: entry?.entries.id, }, }), onSuccess: () => { updateEntry({ - collected: false, + collections: undefined, }) toast({ @@ -77,7 +79,7 @@ export const useEntryActions = ({ apiFetch("/reads", { method: "POST", body: { - entryId: entry?.id, + entryId: entry?.entries.id, }, }), onSuccess: () => { @@ -91,7 +93,7 @@ export const useEntryActions = ({ apiFetch("/reads", { method: "DELETE", body: { - entryId: entry?.id, + entryId: entry?.entries.id, }, }), onSuccess: () => { @@ -103,14 +105,14 @@ export const useEntryActions = ({ const { toast } = useToast() - if (!entry?.url || view === undefined) return { items: [] } + if (!entry?.entries.url || view === undefined) return { items: [] } const items = [ [ { name: "Collect", className: "i-mingcute-star-line", - disabled: !!entry.collected, + disabled: !!entry.collections, onClick: () => { collect.mutate() }, @@ -118,7 +120,7 @@ export const useEntryActions = ({ { name: "Uncollect", className: "i-mingcute-star-fill", - disabled: !entry.collected, + disabled: !entry.collections, onClick: () => { uncollect.mutate() }, @@ -127,8 +129,8 @@ export const useEntryActions = ({ name: "Copy Link", className: "i-mingcute-link-line", onClick: () => { - if (!entry.url) return - navigator.clipboard.writeText(entry.url) + if (!entry.entries.url) return + navigator.clipboard.writeText(entry.entries.url) toast({ duration: 1000, description: "Link copied to clipboard.", @@ -139,8 +141,8 @@ export const useEntryActions = ({ name: "Open in Browser", className: "i-mingcute-world-2-line", onClick: () => { - if (!entry.url) return - window.open(entry.url, "_blank") + if (!entry.entries.url) return + window.open(entry.entries.url, "_blank") }, }, { @@ -148,12 +150,12 @@ export const useEntryActions = ({ icon: "/eagle.svg", disabled: (checkEagle.isLoading ? true : !checkEagle.data) || - !entry.images?.length, + !entry.entries.images?.length, onClick: async () => { - if (!entry.url || !entry.images?.length) return + if (!entry.entries.url || !entry.entries.images?.length) return const response = await client?.saveToEagle({ - url: entry.url, - images: entry.images, + url: entry.entries.url, + images: entry.entries.images, }) if (response?.status === "success") { toast({ @@ -172,8 +174,8 @@ export const useEntryActions = ({ name: "Share", className: "i-mingcute-share-2-line", onClick: () => { - if (!entry.url) return - client?.showShareMenu(entry.url) + if (!entry.entries.url) return + client?.showShareMenu(entry.entries.url) }, }, { diff --git a/src/renderer/src/hooks/useUpdateEntry.tsx b/src/renderer/src/hooks/useUpdateEntry.tsx index 3c021fa55..71115d1c3 100644 --- a/src/renderer/src/hooks/useUpdateEntry.tsx +++ b/src/renderer/src/hooks/useUpdateEntry.tsx @@ -1,4 +1,4 @@ -import type { EntriesResponse, ListResponse } from "@renderer/lib/types" +import type { TimelineResponse, ListResponse } from "@renderer/lib/types" import { Queries } from "@renderer/queries" import type { InfiniteData, QueryKey } from "@tanstack/react-query" import { useQueryClient } from "@tanstack/react-query" @@ -7,7 +7,7 @@ import { produce } from "immer" export const useUpdateEntry = ({ entryId }: { entryId?: string }) => { const queryClient = useQueryClient() - const updateEntry = (changed: Partial) => { + const updateEntry = (changed: Partial) => { const query = Queries.entries.byId(entryId) query.setData((draft) => { @@ -19,12 +19,12 @@ export const useUpdateEntry = ({ entryId }: { entryId?: string }) => { queryKey: ["entries"], }) entriesData.forEach(([key, data]: [QueryKey, unknown]) => { - const assertData = data as InfiniteData> + const assertData = data as InfiniteData> const finaldata = produce(assertData, (assertData) => { const list = assertData?.pages?.[0]?.data if (list) { for (const item of list) { - if (item.id === entryId) { + if (item.entries.id === entryId) { for (const [key, value] of Object.entries(changed)) { item[key] = value } diff --git a/src/renderer/src/lib/types.ts b/src/renderer/src/lib/types.ts index 8e6c28173..78e6a9381 100644 --- a/src/renderer/src/lib/types.ts +++ b/src/renderer/src/lib/types.ts @@ -20,39 +20,22 @@ export type SubscriptionResponse = Array< >[number] & { unread?: number } > -// export type EntriesResponse = { -// author?: string -// category?: string[] -// changedAt: string -// content?: string -// description?: string -// enclosure?: { -// url: string -// type?: string -// length?: number -// title?: string -// } -// feedId: string -// guid: string -// id: string -// images?: string[] -// publishedAt: string -// readingTime?: number -// title?: string -// url?: string +export type EntryResponse = Exclude< + Extract< + InferResponseType, + { code: 0 } + >["data"], + undefined +> -// feeds: FeedResponse -// collected: boolean -// read: boolean -// }[] -export type EntriesResponse = Array< +export type TimelineResponse = Array< Exclude< Extract< - InferResponseType, + InferResponseType, { code: 0 } >["data"], undefined - > + >[number] > export type ListResponse = { diff --git a/src/renderer/src/queries/entries.ts b/src/renderer/src/queries/entries.ts index 13366b019..00384cf87 100644 --- a/src/renderer/src/queries/entries.ts +++ b/src/renderer/src/queries/entries.ts @@ -4,8 +4,7 @@ import { import { useBizInfiniteQuery } from "@renderer/hooks/useBizQuery" import { levels } from "@renderer/lib/constants" import { defineQuery } from "@renderer/lib/defineQuery" -import type { EntriesResponse, ListResponse } from "@renderer/lib/types" -import { apiClient, apiFetch } from "@renderer/queries/api-fetch" +import { apiClient } from "@renderer/queries/api-fetch" export const entries = { entries: ({ @@ -18,11 +17,9 @@ export const entries = { view?: number }) => defineQuery( - ["entries", level, id], + ["entries", level, id, view], async ({ pageParam }) => { const params: { - category?: string - view?: number feedId?: string feedIdList?: string[] } = {} @@ -31,14 +28,14 @@ export const entries = { } else if (level === levels.feed) { params.feedId = `${id}` } - return await apiFetch>("/entries", { - method: "POST", - body: { - offset: pageParam, + const res = await apiClient.timeline.$post({ + json: { + offset: pageParam as number | undefined, view, ...params, }, }) + return await res.json() }, { rootKey: ["entries"], @@ -51,7 +48,11 @@ export const entries = { if (!id) { throw new UnprocessableEntityError("id is required") } - const res = await apiClient.entries.$get({ query: { id } }) + const res = await apiClient.entries.$get({ + query: { + id, + }, + }) const json = await res.json() return json.data