From 6da197c76bc4d08c80277fc8801a68bfbd413248 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 4 Oct 2024 01:39:56 +0800 Subject: [PATCH] feat: inbox list api --- .../src/modules/discover/inbox-list-form.tsx | 8 +++--- .../src/modules/entry-column/index.tsx | 7 ++--- apps/renderer/src/queries/inboxes.ts | 13 +++++++-- apps/renderer/src/store/inbox/store.ts | 7 +++++ packages/shared/src/hono.ts | 27 +++++++++++++++++++ 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/apps/renderer/src/modules/discover/inbox-list-form.tsx b/apps/renderer/src/modules/discover/inbox-list-form.tsx index 9a5f11562..d79612255 100644 --- a/apps/renderer/src/modules/discover/inbox-list-form.tsx +++ b/apps/renderer/src/modules/discover/inbox-list-form.tsx @@ -15,14 +15,14 @@ import { TableRow, } from "~/components/ui/table" import { apiClient } from "~/lib/api-fetch" -import { FeedViewType } from "~/lib/enum" -import { inboxActions, useInboxByView } from "~/store/inbox" +import { useInboxList } from "~/queries/inboxes" +import { inboxActions } from "~/store/inbox" import { InboxForm } from "./inbox-form" export function DiscoverInboxList() { const { t } = useTranslation() - const inboxes = useInboxByView(FeedViewType.Articles) + const inboxes = useInboxList() const { present } = useModalStack() @@ -50,7 +50,7 @@ export function DiscoverInboxList() { - {inboxes.map((inbox) => ( + {inboxes.data?.map((inbox) => ( {inbox.id} diff --git a/apps/renderer/src/modules/entry-column/index.tsx b/apps/renderer/src/modules/entry-column/index.tsx index ef73b887a..5e3f1eb66 100644 --- a/apps/renderer/src/modules/entry-column/index.tsx +++ b/apps/renderer/src/modules/entry-column/index.tsx @@ -178,9 +178,10 @@ function EntryColumnImpl() { } data-total-count={virtuosoOptions.totalCount} > - {virtuosoOptions.totalCount === 0 && !entries.isLoading && !entries.error && ( - - )} + {virtuosoOptions.totalCount === 0 && + !entries.isLoading && + !entries.error && + feed?.type === "feed" && } - defineQuery(["lists", id], async () => inboxActions.fetchInboxById(id), { - rootKey: ["lists"], + defineQuery(["inboxes", id], async () => inboxActions.fetchInboxById(id), { + rootKey: ["inboxes"], + }), + list: () => + defineQuery(["inboxes"], async () => inboxActions.fetchOwnedInboxes(), { + rootKey: ["inboxes"], }), } @@ -13,3 +17,8 @@ export const useInbox = ({ id }: { id?: string }) => useAuthQuery(inboxes.byId({ id: id! }), { enabled: !!id, }) + +export const useInboxList = () => + useAuthQuery(inboxes.list(), { + enabled: true, + }) diff --git a/apps/renderer/src/store/inbox/store.ts b/apps/renderer/src/store/inbox/store.ts index 6068f256e..791155ba2 100644 --- a/apps/renderer/src/store/inbox/store.ts +++ b/apps/renderer/src/store/inbox/store.ts @@ -47,6 +47,13 @@ class InboxActionStatic { delete state.inboxes[id] }) } + + async fetchOwnedInboxes() { + const res = await apiClient.inboxes.list.$get() + this.upsertMany(res.data) + + return res.data + } } export const inboxActions = new InboxActionStatic() diff --git a/packages/shared/src/hono.ts b/packages/shared/src/hono.ts index 2d28b4485..0dca651ae 100644 --- a/packages/shared/src/hono.ts +++ b/packages/shared/src/hono.ts @@ -4253,6 +4253,33 @@ declare const _routes: hono_hono_base.HonoBase