Skip to content

Commit

Permalink
feat: get feed by url
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed May 31, 2024
1 parent 9534bba commit 23a6049
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/renderer/src/components/discover/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function FollowDialog({
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select a verified email to display" />
<SelectValue />
</SelectTrigger>
</FormControl>
<SelectContent>
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/src/components/entry-column/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { EntryModel } from "@renderer/lib/types"
import type { EntryModel, FeedModel } from "@renderer/lib/types"

export type UniversalItemProps = {
entryId: string
entryPreview?: EntryModel
entryPreview?: EntryModel | {
feeds: FeedModel
}
}

export type FilterTab = "all" | "unread"
4 changes: 2 additions & 2 deletions src/renderer/src/components/feed-icon.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { SiteIcon } from "@renderer/components/site-icon"
import { Image } from "@renderer/components/ui/image"
import type { FeedResponse } from "@renderer/lib/types"
import type { FeedModel } from "@renderer/lib/types"
import { cn } from "@renderer/lib/utils"

export function FeedIcon({
feed,
fallbackUrl,
className,
}: {
feed: FeedResponse
feed: FeedModel
fallbackUrl?: string
className?: string
}) {
Expand Down
31 changes: 20 additions & 11 deletions src/renderer/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,29 +131,38 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
$get: {
input: {
query: {
id: string;
id?: string | undefined;
url?: string | undefined;
};
};
output: {
code: 0;
data: {
feed: {
description: string | null;
title: string | null;
id: string;
image: string | null;
url: string;
siteUrl: string | null;
checkedAt: string;
nextCheckAt: string;
lastModifiedHeader: string | null;
etagHeader: string | null;
ttl: number | null;
errorMessage: string | null;
errorAt: string | null;
description?: string | null | undefined;
title?: string | null | undefined;
id?: string | undefined;
image?: string | null | undefined;
siteUrl?: string | null | undefined;
lastModifiedHeader?: string | null | undefined;
etagHeader?: string | null | undefined;
ttl?: number | null | undefined;
errorMessage?: string | null | undefined;
errorAt?: string | null | undefined;
};
subscriptionCount: number;
readCount: number;
subscription?: {
title: string | null;
userId: string;
feedId: string;
view: number;
category: string | null;
isPrivate: boolean | null;
} | undefined;
};
};
outputFormat: "json";
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export type ActiveList = {
} | null

export type FeedResponse = SubscriptionResponse[number]["feeds"]

export type FeedModel = Extract<
InferResponseType<typeof apiClient.feeds.$get>,
{ code: 0 }
>["data"]["feed"]

export type SubscriptionResponse = Array<
Exclude<
Extract<
Expand Down
26 changes: 19 additions & 7 deletions src/renderer/src/queries/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@ import { defineQuery } from "@renderer/lib/defineQuery"
import { apiClient } from "@renderer/queries/api-fetch"

export const feed = {
byId: (id?: string | null) =>
byId: ({
id,
url,
}: {
id?: string
url?: string
}) =>
defineQuery(
["feed", id],
["feed", id, url],
async () => {
if (!id) {
throw new UnprocessableFeedError("id is required")
if (!id && !url) {
throw new UnprocessableFeedError("id or url is required")
}
const res = await apiClient.feeds.$get({
query: {
id,
url,
},
})
const json = await res.json()
Expand All @@ -30,9 +37,14 @@ export const feed = {

export const useFeed = ({
id,
url,
}: {
id?: string | null
id?: string
url?: string
}) =>
useBizQuery(feed.byId(id), {
enabled: !!id,
useBizQuery(feed.byId({
id,
url,
}), {
enabled: !!id || !!url,
})

0 comments on commit 23a6049

Please sign in to comment.