diff --git a/package.json b/package.json index b15805c2f..2fdfeac89 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,11 @@ "typescript": "^5.4.5", "vite": "^5.2.12" }, + "pnpm": { + "patchedDependencies": { + "hono@4.4.2": "patches/hono@4.4.2.patch" + } + }, "simple-git-hooks": { "pre-commit": "pnpm exec lint-staged" }, diff --git a/patches/hono@4.4.2.patch b/patches/hono@4.4.2.patch new file mode 100644 index 000000000..2f2d8007e --- /dev/null +++ b/patches/hono@4.4.2.patch @@ -0,0 +1,13 @@ +diff --git a/dist/types/client/types.d.ts b/dist/types/client/types.d.ts +index 14af56d34248f101aecdebdd2e56278eac4b0c0d..00f2921985e0fabc90df8397a0c18abd8041c1e7 100644 +--- a/dist/types/client/types.d.ts ++++ b/dist/types/client/types.d.ts +@@ -41,7 +41,7 @@ type ClientResponseOfEndpoint = T extends { + output: infer O; + outputFormat: infer F; + status: infer S; +-} ? ClientResponse : never; ++} ? O : never; + export interface ClientResponse extends globalThis.Response { + readonly body: ReadableStream | null; + readonly bodyUsed: boolean; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9f23bdd14..fc0ad9f47 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,11 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +patchedDependencies: + hono@4.4.2: + hash: ofhxnfpal3nvwlen5lybasjjdm + path: patches/hono@4.4.2.patch + importers: .: @@ -22,7 +27,7 @@ importers: version: 5.0.1 '@hono/auth-js': specifier: 1.0.8 - version: 1.0.8(@auth/core@0.31.0)(hono@4.4.2)(react@18.3.1) + version: 1.0.8(@auth/core@0.31.0)(hono@4.4.2(patch_hash=ofhxnfpal3nvwlen5lybasjjdm))(react@18.3.1) '@hookform/resolvers': specifier: 3.4.2 version: 3.4.2(react-hook-form@7.51.5(react@18.3.1)) @@ -6298,10 +6303,10 @@ snapshots: '@gar/promisify@1.1.3': {} - '@hono/auth-js@1.0.8(@auth/core@0.31.0)(hono@4.4.2)(react@18.3.1)': + '@hono/auth-js@1.0.8(@auth/core@0.31.0)(hono@4.4.2(patch_hash=ofhxnfpal3nvwlen5lybasjjdm))(react@18.3.1)': dependencies: '@auth/core': 0.31.0 - hono: 4.4.2 + hono: 4.4.2(patch_hash=ofhxnfpal3nvwlen5lybasjjdm) react: 18.3.1 '@hookform/resolvers@3.4.2(react-hook-form@7.51.5(react@18.3.1))': @@ -9150,7 +9155,7 @@ snapshots: dependencies: hermes-estree: 0.20.1 - hono@4.4.2: {} + hono@4.4.2(patch_hash=ofhxnfpal3nvwlen5lybasjjdm): {} hosted-git-info@2.8.9: {} diff --git a/src/renderer/src/components/discover/form.tsx b/src/renderer/src/components/discover/form.tsx index 7134431a0..57e7c9bcb 100644 --- a/src/renderer/src/components/discover/form.tsx +++ b/src/renderer/src/components/discover/form.tsx @@ -16,8 +16,7 @@ import { } from "@renderer/components/ui/form" import { Image } from "@renderer/components/ui/image" import { Input } from "@renderer/components/ui/input" -import type { DiscoverResponse } from "@renderer/models" -import { apiFetch } from "@renderer/queries/api-fetch" +import { apiClient } from "@renderer/lib/api-fetch" import { DEEPLINK_SCHEME } from "@shared/constants" import { openElectronWindow } from "@shared/electron" import { useMutation } from "@tanstack/react-query" @@ -64,15 +63,13 @@ export function DiscoverForm({ type }: { type: string }) { }) const mutation = useMutation({ mutationFn: async (keyword: string) => { - const { data } = await apiFetch<{ - data: DiscoverResponse - }>("/discover", { - method: "POST", - body: { + const { data } = await apiClient.discover.$post({ + json: { keyword, type: type === "rss" ? "rss" : "auto", }, }) + return data }, }) diff --git a/src/renderer/src/components/discover/import.tsx b/src/renderer/src/components/discover/import.tsx index f859e27f8..a8d4ca04a 100644 --- a/src/renderer/src/components/discover/import.tsx +++ b/src/renderer/src/components/discover/import.tsx @@ -10,10 +10,10 @@ import { FormMessage, } from "@renderer/components/ui/form" import { Input } from "@renderer/components/ui/input" +import { apiFetch } from "@renderer/lib/api-fetch" import { cn } from "@renderer/lib/utils" import type { FeedResponse } from "@renderer/models" import { Queries } from "@renderer/queries" -import { apiFetch } from "@renderer/queries/api-fetch" import { useMutation } from "@tanstack/react-query" import { useForm } from "react-hook-form" import { z } from "zod" @@ -59,6 +59,8 @@ export function DiscoverImport() { mutationFn: async (file: File) => { const formData = new FormData() formData.append("file", file) + // FIXME: if post data is form data, hono hc not support this. + const { data } = await apiFetch<{ data: { successfulItems: FeedResponseList @@ -69,6 +71,7 @@ export function DiscoverImport() { method: "POST", body: formData, }) + return data }, onSuccess: () => { diff --git a/src/renderer/src/components/entry-column/index.tsx b/src/renderer/src/components/entry-column/index.tsx index 70b2f84d4..223cd45ea 100644 --- a/src/renderer/src/components/entry-column/index.tsx +++ b/src/renderer/src/components/entry-column/index.tsx @@ -5,12 +5,12 @@ import { PopoverContent, PopoverTrigger, } from "@renderer/components/ui/popover" +import { apiClient } from "@renderer/lib/api-fetch" import { views } from "@renderer/lib/constants" import { FeedViewType } from "@renderer/lib/enum" import { buildStorageNS } from "@renderer/lib/ns" import { getEntriesParams } from "@renderer/lib/utils" import type { EntryModel } from "@renderer/models" -import { apiClient } from "@renderer/queries/api-fetch" import { useEntries } from "@renderer/queries/entries" import { feedActions, diff --git a/src/renderer/src/components/entry-column/item-wrapper.tsx b/src/renderer/src/components/entry-column/item-wrapper.tsx index 3f78b54d5..8acbc2b5b 100644 --- a/src/renderer/src/components/entry-column/item-wrapper.tsx +++ b/src/renderer/src/components/entry-column/item-wrapper.tsx @@ -1,8 +1,8 @@ import { useEntryActions } from "@renderer/hooks/useEntryActions" +import { apiClient } from "@renderer/lib/api-fetch" import { views } from "@renderer/lib/constants" import { showNativeMenu } from "@renderer/lib/native-menu" import { cn } from "@renderer/lib/utils" -import { apiClient } from "@renderer/queries/api-fetch" import { feedActions, useFeedStore } from "@renderer/store" import { entryActions, useEntry } from "@renderer/store/entry" import { useMutation } from "@tanstack/react-query" diff --git a/src/renderer/src/components/feed-column/category-remove-dialog.tsx b/src/renderer/src/components/feed-column/category-remove-dialog.tsx index 36df73793..f95c52179 100644 --- a/src/renderer/src/components/feed-column/category-remove-dialog.tsx +++ b/src/renderer/src/components/feed-column/category-remove-dialog.tsx @@ -7,8 +7,8 @@ import { AlertDialogHeader, AlertDialogTitle, } from "@renderer/components/ui/alert-dialog" +import { apiClient } from "@renderer/lib/api-fetch" import { Queries } from "@renderer/queries" -import { apiFetch } from "@renderer/queries/api-fetch" import { useMutation } from "@tanstack/react-query" export function CategoryRemoveDialog({ @@ -24,9 +24,9 @@ export function CategoryRemoveDialog({ }) { const renameMutation = useMutation({ mutationFn: async () => - apiFetch("/categories", { - method: "DELETE", - body: { + + apiClient.categories.$delete({ + json: { feedIdList, deleteSubscriptions: false, }, diff --git a/src/renderer/src/components/feed-column/category-rename-dialog.tsx b/src/renderer/src/components/feed-column/category-rename-dialog.tsx index 02d39002c..e1b7c028e 100644 --- a/src/renderer/src/components/feed-column/category-rename-dialog.tsx +++ b/src/renderer/src/components/feed-column/category-rename-dialog.tsx @@ -13,8 +13,8 @@ import { FormMessage, } from "@renderer/components/ui/form" import { Input } from "@renderer/components/ui/input" +import { apiClient } from "@renderer/lib/api-fetch" import { Queries } from "@renderer/queries" -import { apiFetch } from "@renderer/queries/api-fetch" import { useMutation } from "@tanstack/react-query" import { useForm } from "react-hook-form" import { z } from "zod" @@ -43,9 +43,9 @@ export function CategoryRenameDialog({ const renameMutation = useMutation({ mutationFn: async (values: z.infer) => - apiFetch("/categories", { - method: "PATCH", - body: { + + apiClient.categories.$patch({ + json: { feedIdList, category: values.category, }, @@ -58,7 +58,6 @@ export function CategoryRenameDialog({ }) function onSubmit(values: z.infer) { - console.log("onSubmit", values) renameMutation.mutate(values) } diff --git a/src/renderer/src/components/feed-column/category.tsx b/src/renderer/src/components/feed-column/category.tsx index 22c6fa4f6..b344624b6 100644 --- a/src/renderer/src/components/feed-column/category.tsx +++ b/src/renderer/src/components/feed-column/category.tsx @@ -3,13 +3,13 @@ import { CollapsibleTrigger, } from "@renderer/components/ui/collapsible" import { Dialog } from "@renderer/components/ui/dialog" +import { apiClient } from "@renderer/lib/api-fetch" import { client } from "@renderer/lib/client" import { levels } from "@renderer/lib/constants" import { showNativeMenu } from "@renderer/lib/native-menu" import { cn } from "@renderer/lib/utils" import type { FeedListModel } from "@renderer/models" import { Queries } from "@renderer/queries" -import { apiFetch } from "@renderer/queries/api-fetch" import { feedActions, useFeedActiveList, @@ -41,13 +41,13 @@ export function FeedCategory({ const feedIdList = data.list.map((feed) => feed.feedId) const deleteMutation = useMutation({ mutationFn: async () => - apiFetch("/categories", { - method: "DELETE", - body: { + apiClient.categories.$delete({ + json: { feedIdList, deleteSubscriptions: false, }, }), + onSuccess: () => { Queries.subscription.byView(view).invalidate() }, diff --git a/src/renderer/src/components/feed-column/item.tsx b/src/renderer/src/components/feed-column/item.tsx index 211076d1b..077afdaa6 100644 --- a/src/renderer/src/components/feed-column/item.tsx +++ b/src/renderer/src/components/feed-column/item.tsx @@ -8,13 +8,13 @@ import { TooltipTrigger, } from "@renderer/components/ui/tooltip" import { useToast } from "@renderer/components/ui/use-toast" +import { apiClient } from "@renderer/lib/api-fetch" import { levels } from "@renderer/lib/constants" import dayjs from "@renderer/lib/dayjs" import { showNativeMenu } from "@renderer/lib/native-menu" import { cn } from "@renderer/lib/utils" import type { SubscriptionResponse } from "@renderer/models" import { Queries } from "@renderer/queries" -import { apiFetch } from "@renderer/queries/api-fetch" import { feedActions, useFeedActiveList, @@ -49,12 +49,12 @@ export function FeedItem({ const deleteMutation = useMutation({ mutationFn: async (feed: SubscriptionResponse[number]) => - apiFetch("/subscriptions", { - method: "DELETE", - body: { + apiClient.subscriptions.$delete({ + json: { feedId: feed.feedId, }, }), + onSuccess: (_, variables) => { Queries.subscription.byView(variables.view).invalidate() @@ -73,11 +73,10 @@ export function FeedItem({ { - await apiFetch("/subscriptions", { - method: "POST", - body: { + await apiClient.subscriptions.$post({ + json: { url: variables.feeds.url, - view: feed.view, + view: variables.view, category: variables.category, isPrivate: variables.isPrivate, }, diff --git a/src/renderer/src/hooks/useEntryActions.tsx b/src/renderer/src/hooks/useEntryActions.tsx index c9d317a77..1c69d265e 100644 --- a/src/renderer/src/hooks/useEntryActions.tsx +++ b/src/renderer/src/hooks/useEntryActions.tsx @@ -1,7 +1,7 @@ import { useToast } from "@renderer/components/ui/use-toast" +import { apiClient } from "@renderer/lib/api-fetch" import { client } from "@renderer/lib/client" -import type { EntriesResponse } from "@renderer/models" -import { apiClient, apiFetch } from "@renderer/queries/api-fetch" +import type { EntryModel } from "@renderer/models" import { entryActions } from "@renderer/store/entry" import { useMutation, useQuery } from "@tanstack/react-query" import type { FetchError } from "ofetch" @@ -12,7 +12,7 @@ export const useEntryActions = ({ entry, }: { view?: number - entry?: EntriesResponse[number] + entry?: EntryModel }) => { const checkEagle = useQuery({ queryKey: ["check-eagle"], @@ -29,12 +29,12 @@ export const useEntryActions = ({ const collect = useMutation({ mutationFn: async () => - apiFetch("/collections", { - method: "POST", - body: { + entry && apiClient.collections.$post({ + json: { entryId: entry?.entries.id, }, }), + onMutate() { if (!entry) return entryActions.optimisticUpdate(entry.entries.id, { @@ -52,12 +52,12 @@ export const useEntryActions = ({ }) const uncollect = useMutation({ mutationFn: async () => - apiFetch("/collections", { - method: "DELETE", - body: { + entry && apiClient.collections.$delete({ + json: { entryId: entry?.entries.id, }, }), + onMutate() { if (!entry) return entryActions.optimisticUpdate(entry.entries.id, { @@ -87,13 +87,12 @@ export const useEntryActions = ({ }, }) const unread = useMutation({ - mutationFn: async () => - apiFetch("/reads", { - method: "DELETE", - body: { - entryId: entry?.entries.id, - }, - }), + mutationFn: async () => entry && apiClient.reads.$delete({ + json: { + entryId: entry.entries.id, + }, + }), + onMutate: () => { if (!entry) return diff --git a/src/renderer/src/lib/api-fetch.ts b/src/renderer/src/lib/api-fetch.ts new file mode 100644 index 000000000..6c08d7f09 --- /dev/null +++ b/src/renderer/src/lib/api-fetch.ts @@ -0,0 +1,30 @@ +import { getCsrfToken } from "@hono/auth-js/react" +import type { AppType } from "@renderer/hono" +import { hc } from "hono/client" +import { ofetch } from "ofetch" + +export const apiFetch = ofetch.create({ + baseURL: import.meta.env.VITE_API_URL, + credentials: "include", + onRequest: async ({ options }) => { + if (options.method && options.method.toLowerCase() !== "get") { + const csrfToken = await getCsrfToken() + + if (typeof options.body === "string") { + options.body = JSON.parse(options.body) + } + if (!options.body) { + options.body = {} + } + if (options.body instanceof FormData) { + options.body.append("csrfToken", csrfToken) + } else { + (options.body as Record).csrfToken = csrfToken + } + } + }, +}) + +export const apiClient = hc("", { + fetch: async (input, options = {}) => apiFetch(input.toString(), options), +}) diff --git a/src/renderer/src/lib/enum.ts b/src/renderer/src/lib/enum.ts index df7682a16..a303d97b1 100644 --- a/src/renderer/src/lib/enum.ts +++ b/src/renderer/src/lib/enum.ts @@ -1,4 +1,3 @@ -// eslint-disable-next-line no-restricted-syntax export enum FeedViewType { Articles = 0, SocialMedia = 1, diff --git a/src/renderer/src/models/types.ts b/src/renderer/src/models/types.ts index f6a1f8ec6..7bb0e1e9a 100644 --- a/src/renderer/src/models/types.ts +++ b/src/renderer/src/models/types.ts @@ -1,5 +1,9 @@ -import type { apiClient } from "@renderer/queries/api-fetch" -import type { InferResponseType } from "hono/client" +import type { apiClient } from "@renderer/lib/api-fetch" + +export type ExtractBizResponse any> = Exclude< + Awaited>, + undefined +> export type ActiveList = { level: string @@ -11,24 +15,19 @@ export type ActiveList = { export type FeedResponse = SubscriptionResponse[number]["feeds"] -export type FeedModel = Extract< - InferResponseType, - { code: 0 } +export type FeedModel = ExtractBizResponse< + typeof apiClient.feeds.$get >["data"]["feed"] export type SubscriptionResponse = Array< - Exclude< - Extract< - InferResponseType, - { code: 0 } - >["data"], - undefined - >[number] & { unread?: number } + ExtractBizResponse["data"][number] & { + unread?: number + } > export type EntryResponse = Exclude< Extract< - InferResponseType, + ExtractBizResponse, { code: 0 } >["data"], undefined @@ -36,18 +35,15 @@ export type EntryResponse = Exclude< export type EntriesResponse = Array< Exclude< - Extract< - InferResponseType, - { code: 0 } - >["data"], + Awaited>["data"], undefined - >[number] -> + > +>[number] export type EntryModel = EntriesResponse[number] export type DiscoverResponse = Array< Exclude< - InferResponseType["data"], + ExtractBizResponse["data"], undefined >[number] > diff --git a/src/renderer/src/pages/(external)/redirect.tsx b/src/renderer/src/pages/(external)/redirect.tsx index 31e48bc5b..da1949d1f 100644 --- a/src/renderer/src/pages/(external)/redirect.tsx +++ b/src/renderer/src/pages/(external)/redirect.tsx @@ -1,7 +1,7 @@ import { Button } from "@renderer/components/ui/button" import { UserButton } from "@renderer/components/user-button" +import { apiClient } from "@renderer/lib/api-fetch" import { APP_NAME } from "@renderer/lib/constants" -import { apiFetch } from "@renderer/queries/api-fetch" import { DEEPLINK_SCHEME } from "@shared/constants" import { useEffect } from "react" import { useNavigate } from "react-router-dom" @@ -10,13 +10,7 @@ export function Component() { const navigate = useNavigate() const getCallbackUrl = async () => { - const { data } = await apiFetch<{ - data: { - sessionToken: string - } - }>("/auth-app/new-session", { - method: "POST", - }) + const { data } = await apiClient["auth-app"]["new-session"].$post({}) return `${DEEPLINK_SCHEME}auth?token=${data.sessionToken}` } @@ -44,8 +38,8 @@ export function Component() { {" "} {APP_NAME} {" "} - Account. Now is the time to - open + Account. Now is the time + to open {" "} {APP_NAME} {" "} diff --git a/src/renderer/src/pages/add/index.tsx b/src/renderer/src/pages/add/index.tsx index f5a5cd43f..8f4e36d16 100644 --- a/src/renderer/src/pages/add/index.tsx +++ b/src/renderer/src/pages/add/index.tsx @@ -22,11 +22,11 @@ import { import { Switch } from "@renderer/components/ui/switch" import { useToast } from "@renderer/components/ui/use-toast" import { useBizQuery } from "@renderer/hooks/useBizQuery" +import { apiClient } from "@renderer/lib/api-fetch" import { client } from "@renderer/lib/client" import { views } from "@renderer/lib/constants" import { cn } from "@renderer/lib/utils" import { Queries } from "@renderer/queries" -import { apiFetch } from "@renderer/queries/api-fetch" import { useFeed } from "@renderer/queries/feed" import { useMutation } from "@tanstack/react-query" import { useEffect } from "react" @@ -68,17 +68,20 @@ export function Component() { const { toast } = useToast() const followMutation = useMutation({ - mutationFn: async (values: z.infer) => - apiFetch("/subscriptions", { - method: isSubscribed ? "PATCH" : "POST", - body: { - url: feed.data?.feed.url, - view: Number.parseInt(values.view), - category: values.category, - isPrivate: values.isPrivate, - ...(isSubscribed && { feedId: feed.data?.feed.id }), - }, - }), + mutationFn: async (values: z.infer) => { + const body = { + url: feed.data?.feed.url, + view: Number.parseInt(values.view), + category: values.category, + isPrivate: values.isPrivate, + ...(isSubscribed && { feedId: feed.data?.feed.id }), + } + const $method = isSubscribed ? apiClient.subscriptions.$patch : apiClient.subscriptions.$post + $method({ + // @ts-expect-error + json: body, + }) + }, onSuccess: (_, variables) => { if ( isSubscribed && @@ -122,116 +125,114 @@ export function Component() { logo Add follow - {feed.isLoading ? + {feed.isLoading ? ( +
+ Loading... +
+ ) : !feed.data?.feed ? ( -
- Loading... +
+

Feed not found.

+

{url}

) : - !feed.data?.feed ? - ( -
-

Feed not found.

-

{url}

-
- ) : - ( -
- - - - - -
- - ( - - View - - - - )} - /> - ( - -
- Category - - By default, your follows will be grouped by website. - -
- - - - -
- )} - /> - ( - -
-
- Private Follow - - Whether this follow is publicly visible on your - profile page. - -
- - - -
-
- )} - /> -
- -
- - -
- )} + ( +
+ + + + + +
+ + ( + + View + + + + )} + /> + ( + +
+ Category + + By default, your follows will be grouped by website. + +
+ + + + +
+ )} + /> + ( + +
+
+ Private Follow + + Whether this follow is publicly visible on your + profile page. + +
+ + + +
+
+ )} + /> +
+ +
+ + +
+ )}
) } diff --git a/src/renderer/src/pages/settings/profile.tsx b/src/renderer/src/pages/settings/profile.tsx index dca0d0780..e8469764f 100644 --- a/src/renderer/src/pages/settings/profile.tsx +++ b/src/renderer/src/pages/settings/profile.tsx @@ -12,7 +12,7 @@ import { } from "@renderer/components/ui/form" import { Input } from "@renderer/components/ui/input" import { useToast } from "@renderer/components/ui/use-toast" -import { apiFetch } from "@renderer/queries/api-fetch" +import { apiClient } from "@renderer/lib/api-fetch" import { useMutation } from "@tanstack/react-query" import { useForm } from "react-hook-form" import { z } from "zod" @@ -39,9 +39,8 @@ export function Component() { const updateMutation = useMutation({ mutationFn: async (values: z.infer) => - apiFetch("/auth-app/update-account", { - method: "PATCH", - body: values, + apiClient["auth-app"]["update-account"].$patch({ + json: values, }), onSuccess: () => { toast({ diff --git a/src/renderer/src/queries/api-fetch.ts b/src/renderer/src/queries/api-fetch.ts deleted file mode 100644 index ddec931f2..000000000 --- a/src/renderer/src/queries/api-fetch.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { getCsrfToken } from "@hono/auth-js/react" -import type { AppType } from "@renderer/hono" -import { hc } from "hono/client" -import { ofetch } from "ofetch" - -export const apiFetch = ofetch.create({ - baseURL: import.meta.env.VITE_API_URL, - credentials: "include", - onRequest: async ({ options }) => { - if (options.method && options.method.toLowerCase() !== "get") { - const csrfToken = await getCsrfToken() - if (!options.body) { - options.body = {} - } - if (options.body instanceof FormData) { - options.body.append("csrfToken", csrfToken) - } else { - ;(options.body as Record).csrfToken = csrfToken - } - } - }, -}) - -export const apiClient = hc( - import.meta.env.VITE_API_URL, - { - fetch: async (...args) => { - const options = args[1] as RequestInit - options.credentials = "include" - if (options.method && options.method.toLowerCase() !== "get") { - const csrfToken = await getCsrfToken() - if (!options.body) { - options.body = JSON.stringify({}) - } - if (options.body instanceof FormData) { - options.body.append("csrfToken", csrfToken) - } else { - if (typeof options.body === "string") { - options.body = JSON.stringify({ csrfToken, ...JSON.parse(options.body) }) - } - } - } - return fetch(args[0], options) - }, - }, -) diff --git a/src/renderer/src/queries/entries.ts b/src/renderer/src/queries/entries.ts index afe0efff6..848957d4c 100644 --- a/src/renderer/src/queries/entries.ts +++ b/src/renderer/src/queries/entries.ts @@ -1,7 +1,7 @@ import { UnprocessableEntityError } from "@renderer/biz/error" import { useBizInfiniteQuery, useBizQuery } from "@renderer/hooks/useBizQuery" +import { apiClient } from "@renderer/lib/api-fetch" import { defineQuery } from "@renderer/lib/defineQuery" -import { apiClient } from "@renderer/queries/api-fetch" import { entryActions } from "@renderer/store/entry" export const entries = { @@ -42,9 +42,8 @@ export const entries = { id, }, }) - const json = await res.json() - return json.data + return res.data }, { rootKey: ["entries"], @@ -59,9 +58,8 @@ export const entries = { id, }, }) - const json = await res.json() - return json.data + return res.data }, { rootKey: ["entries-preview"], diff --git a/src/renderer/src/queries/feed.ts b/src/renderer/src/queries/feed.ts index 53e64cd25..6432bb1dc 100644 --- a/src/renderer/src/queries/feed.ts +++ b/src/renderer/src/queries/feed.ts @@ -2,8 +2,8 @@ import { UnprocessableFeedError, } from "@renderer/biz/error" import { useBizQuery } from "@renderer/hooks/useBizQuery" +import { apiClient } from "@renderer/lib/api-fetch" import { defineQuery } from "@renderer/lib/defineQuery" -import { apiClient } from "@renderer/queries/api-fetch" export const feed = { byId: ({ @@ -25,9 +25,8 @@ export const feed = { url, }, }) - const json = await res.json() - return json.data + return res.data }, { rootKey: ["feed"], diff --git a/src/renderer/src/queries/subscriptions.ts b/src/renderer/src/queries/subscriptions.ts index 031202e85..4181162dc 100644 --- a/src/renderer/src/queries/subscriptions.ts +++ b/src/renderer/src/queries/subscriptions.ts @@ -1,6 +1,6 @@ +import { apiClient } from "@renderer/lib/api-fetch" import { defineQuery } from "@renderer/lib/defineQuery" import type { FeedViewType } from "@renderer/lib/enum" -import { apiClient } from "@renderer/queries/api-fetch" import { subscriptionActions, unreadActions } from "@renderer/store" export const subscription = { @@ -23,11 +23,9 @@ export const subscription = { ), categories: (view?: number) => defineQuery(["subscription-categories", view], async () => { - const res = await ( - await apiClient.categories.$get({ - query: { view: String(view) }, - }) - ).json() + const res = await apiClient.categories.$get({ + query: { view: String(view) }, + }) return res.data }), diff --git a/src/renderer/src/store/entry.ts b/src/renderer/src/store/entry.ts index 8b38f896d..6bcb79da0 100644 --- a/src/renderer/src/store/entry.ts +++ b/src/renderer/src/store/entry.ts @@ -1,7 +1,6 @@ +import { apiClient } from "@renderer/lib/api-fetch" import { getEntriesParams } from "@renderer/lib/utils" import type { EntryModel } from "@renderer/models" -import { apiClient } from "@renderer/queries/api-fetch" -import type { InferResponseType } from "hono/client" import { produce } from "immer" import { omit } from "lodash-es" @@ -26,7 +25,7 @@ interface EntryActions { read?: boolean pageParam?: string - }) => Promise> + }) => Promise>> upsertMany: (entries: EntryModel[]) => void optimisticUpdate: (entryId: string, changed: Partial) => void @@ -54,7 +53,7 @@ export const useEntryStore = createZustandStore( pageParam, }) => { - const res = await apiClient.entries.$post({ + const data = await apiClient.entries.$post({ json: { publishedAfter: pageParam as string, read, @@ -66,8 +65,6 @@ export const useEntryStore = createZustandStore( }, }) - const data = await res.json() - if (data.data) { get().upsertMany(data.data) } diff --git a/src/renderer/src/store/subscription.ts b/src/renderer/src/store/subscription.ts index de0b7c3f4..e50039dac 100644 --- a/src/renderer/src/store/subscription.ts +++ b/src/renderer/src/store/subscription.ts @@ -1,6 +1,6 @@ +import { apiClient } from "@renderer/lib/api-fetch" import type { FeedViewType } from "@renderer/lib/enum" import type { SubscriptionModel } from "@renderer/models" -import { apiClient } from "@renderer/queries/api-fetch" import { produce } from "immer" import { omit } from "lodash-es" @@ -23,11 +23,11 @@ export const useSubscriptionStore = createZustandStore< data: {}, async fetchByView(view) { - const res = await ( - await apiClient.subscriptions.$get({ query: { view: String(view) } }) - ).json() + const res = await apiClient.subscriptions.$get({ + query: { view: String(view) }, + }) - res.data.forEach((subscription: SubscriptionModel) => { + res.data.forEach((subscription) => { set((state) => produce(state, (state) => { state.data[subscription.feeds.id] = subscription diff --git a/src/renderer/src/store/unread.ts b/src/renderer/src/store/unread.ts index 3c013ce52..a6b9eb914 100644 --- a/src/renderer/src/store/unread.ts +++ b/src/renderer/src/store/unread.ts @@ -1,5 +1,5 @@ +import { apiClient } from "@renderer/lib/api-fetch" import type { FeedViewType } from "@renderer/lib/enum" -import { apiClient } from "@renderer/queries/api-fetch" import { produce } from "immer" import { omit } from "lodash-es" @@ -19,9 +19,9 @@ export const useUnreadStore = createZustandStore( data: {}, async fetchUnreadByView(view) { - const unread = await ( + const unread = ( await apiClient.reads.$get({ query: { view: String(view) } }) - ).json() + ) const { data } = unread for (const feedId in data) {