From 070c26736c62e1443a5b007f4a6cc51fb91fe133 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 22 Jul 2024 13:03:26 +0800 Subject: [PATCH] feat: discover rss3 --- src/renderer/src/hono.ts | 3 +- .../modules/discover/content-components.tsx | 38 +++++++++++-------- src/renderer/src/modules/discover/form.tsx | 5 --- .../src/modules/discover/rss3-form.tsx | 27 +++++++++++++ .../(layer)/(subview)/discover/index.tsx | 13 +++---- src/renderer/src/queries/discover.ts | 15 +++++++- 6 files changed, 71 insertions(+), 30 deletions(-) create mode 100644 src/renderer/src/modules/discover/rss3-form.tsx diff --git a/src/renderer/src/hono.ts b/src/renderer/src/hono.ts index 922b6a3adb..0b908cc5b6 100644 --- a/src/renderer/src/hono.ts +++ b/src/renderer/src/hono.ts @@ -3020,7 +3020,8 @@ declare const _routes: hono_hono_base.HonoBase { export const DiscoverFeedForm = ({ route, routePrefix, + noDescription, + submitButtonClassName, }: { route: RSSHubRoute routePrefix: string + noDescription?: boolean + submitButtonClassName?: string }) => { const keys = useMemo( () => @@ -176,18 +181,20 @@ export const DiscoverFeedForm = ({ $form.querySelectorAll("input")[0]?.focus() }, [formElRef]) - const { setClickOutSideToDismiss } = useCurrentModal() + const modal = useCurrentModal() useEffect(() => { - setClickOutSideToDismiss(!form.formState.isDirty) - }, [form.formState.isDirty, setClickOutSideToDismiss]) + modal?.setClickOutSideToDismiss?.(!form.formState.isDirty) + }, [form.formState.isDirty, modal?.setClickOutSideToDismiss]) return (
- + {!noDescription && ( + + )} - + {keyItem.name} {!keyItem.optional && ( * @@ -247,12 +254,13 @@ export const DiscoverFeedForm = ({ ) })} - - - - - -
+ {!noDescription && ( + <> + + + + )} +
Preview
diff --git a/src/renderer/src/modules/discover/form.tsx b/src/renderer/src/modules/discover/form.tsx index 829ea8d582..dcad2c01d5 100644 --- a/src/renderer/src/modules/discover/form.tsx +++ b/src/renderer/src/modules/discover/form.tsx @@ -19,7 +19,6 @@ import { Image } from "@renderer/components/ui/image" import { Input } from "@renderer/components/ui/input" import { useModalStack } from "@renderer/components/ui/modal/stacked/hooks" import { apiClient } from "@renderer/lib/api-fetch" -import { DEEPLINK_SCHEME } from "@shared/constants" import { useMutation } from "@tanstack/react-query" import { useEffect } from "react" import { useForm } from "react-hook-form" @@ -49,10 +48,6 @@ const info: Record< label: "RSSHub Route", prefix: "rsshub://", }, - user: { - label: "User Handle", - prefix: DEEPLINK_SCHEME, - }, } export function DiscoverForm({ type }: { type: string }) { diff --git a/src/renderer/src/modules/discover/rss3-form.tsx b/src/renderer/src/modules/discover/rss3-form.tsx new file mode 100644 index 0000000000..251d379840 --- /dev/null +++ b/src/renderer/src/modules/discover/rss3-form.tsx @@ -0,0 +1,27 @@ +import { useAuthQuery } from "@renderer/hooks/common" +import { Queries } from "@renderer/queries" + +import { DiscoverFeedForm } from "./content-components" + +export function DiscoverRSS3() { + const { data } = useAuthQuery( + Queries.discover.rsshubNamespace({ + namespace: "rss3", + }), + ) + + return ( + <> + {data?.rss3.routes && ( +
+ +
+ )} + + ) +} diff --git a/src/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx b/src/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx index 01a1e74c95..cbacc9a354 100644 --- a/src/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx +++ b/src/renderer/src/pages/(main)/(layer)/(subview)/discover/index.tsx @@ -7,6 +7,7 @@ import { import { DiscoverForm } from "@renderer/modules/discover/form" import { DiscoverImport } from "@renderer/modules/discover/import" import { Recommendations } from "@renderer/modules/discover/recommendations" +import { DiscoverRSS3 } from "@renderer/modules/discover/rss3-form" export function Component() { const tabs = [ @@ -22,15 +23,9 @@ export function Component() { name: "RSSHub", value: "rsshub", }, - { - name: "Follow User", - value: "user", - disabled: true, - }, { name: "RSS3", value: "rss3", - disabled: true, }, { name: "Email", @@ -60,9 +55,11 @@ export function Component() { {tabs.map((tab) => ( - {tab.value === "import" ? + {tab.value === "import" ? ( + + ) : tab.value === "rss3" ? ( - + ) : ( diff --git a/src/renderer/src/queries/discover.ts b/src/renderer/src/queries/discover.ts index dd59037995..9d7ee70b53 100644 --- a/src/renderer/src/queries/discover.ts +++ b/src/renderer/src/queries/discover.ts @@ -7,7 +7,7 @@ export const discover = { }: { category: string }) => - defineQuery(["discover", "rsshub", category], async () => { + defineQuery(["discover", "rsshub", "category", category], async () => { const res = await apiClient.discover.rsshub.$get({ query: { category, @@ -15,4 +15,17 @@ export const discover = { }) return res.data }), + rsshubNamespace: ({ + namespace, + }: { + namespace: string + }) => + defineQuery(["discover", "rsshub", "namespace", namespace], async () => { + const res = await apiClient.discover.rsshub.$get({ + query: { + namespace, + }, + }) + return res.data + }), }