diff --git a/src/renderer/src/components/subscribe/follow-user-form.tsx b/src/renderer/src/components/subscribe/form.tsx similarity index 57% rename from src/renderer/src/components/subscribe/follow-user-form.tsx rename to src/renderer/src/components/subscribe/form.tsx index c6a767fc4..7c1804c5b 100644 --- a/src/renderer/src/components/subscribe/follow-user-form.tsx +++ b/src/renderer/src/components/subscribe/form.tsx @@ -14,38 +14,63 @@ import { Input } from "@renderer/components/ui/input" import { useEffect } from "react" const formSchema = z.object({ - url: z.string().min(1), + keyword: z.string().min(1), }) -export function FollowUserForm() { +const info: { + [key: string]: { + label: string + prefix?: string + } +} = { + general: { + label: "Any URL or Keyword", + }, + rss: { + label: "RSS URL", + }, + rsshub: { + label: "RSSHub Route", + prefix: "rsshub://", + }, + user: { + label: "User Handle", + prefix: "follow://", + }, +} + +export function SubscribeForm({ type }: { type: string }) { + const prefix = info[type].prefix const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { - url: "", + keyword: prefix, }, }) function onSubmit(values: z.infer) { console.log(values) } - const url = form.watch("url") + const keyword = form.watch("keyword") useEffect(() => { - if (!url.startsWith("follow://")) { - form.setValue("url", "follow://") - } else if (url.startsWith("follow://follow://")) { - form.setValue("url", url.slice(9)) + if (prefix) { + if (!keyword.startsWith(prefix)) { + form.setValue("keyword", prefix) + } else if (keyword.startsWith(`${prefix}${prefix}`)) { + form.setValue("keyword", keyword.slice(prefix.length)) + } } - }, [url]) + }, [keyword]) return (
( - User Handle + {info[type]?.label} diff --git a/src/renderer/src/components/subscribe/rss-form.tsx b/src/renderer/src/components/subscribe/rss-form.tsx deleted file mode 100644 index c01011a6e..000000000 --- a/src/renderer/src/components/subscribe/rss-form.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { z } from "zod" -import { zodResolver } from "@hookform/resolvers/zod" -import { useForm } from "react-hook-form" -import { Button } from "@renderer/components/ui/button" -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@renderer/components/ui/form" -import { Input } from "@renderer/components/ui/input" - -const formSchema = z.object({ - url: z.string().min(1), -}) - -export function RSSForm() { - const form = useForm>({ - resolver: zodResolver(formSchema), - defaultValues: { - url: "", - }, - }) - function onSubmit(values: z.infer) { - console.log(values) - } - - return ( - - - ( - - URL or Keyword - - - - - - )} - /> - - - - ) -} diff --git a/src/renderer/src/components/subscribe/rsshub-form.tsx b/src/renderer/src/components/subscribe/rsshub-form.tsx deleted file mode 100644 index ad8692a35..000000000 --- a/src/renderer/src/components/subscribe/rsshub-form.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import { z } from "zod" -import { zodResolver } from "@hookform/resolvers/zod" -import { useForm } from "react-hook-form" -import { Button } from "@renderer/components/ui/button" -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@renderer/components/ui/form" -import { Input } from "@renderer/components/ui/input" -import { useEffect } from "react" - -const formSchema = z.object({ - url: z.string().min(1), -}) - -export function RSSHubForm() { - const form = useForm>({ - resolver: zodResolver(formSchema), - defaultValues: { - url: "rsshub://", - }, - }) - function onSubmit(values: z.infer) { - console.log(values) - } - - const url = form.watch("url") - useEffect(() => { - if (!url.startsWith("rsshub://")) { - form.setValue("url", "rsshub://") - } else if (url.startsWith("rsshub://rsshub://")) { - form.setValue("url", url.slice(9)) - } - }, [url]) - - return ( -
- - ( - - RSSHub Route - - - - - - )} - /> - - - - ) -} diff --git a/src/renderer/src/pages/(main)/subscribe/index.tsx b/src/renderer/src/pages/(main)/subscribe/index.tsx index 5c6536e74..0a243111c 100644 --- a/src/renderer/src/pages/(main)/subscribe/index.tsx +++ b/src/renderer/src/pages/(main)/subscribe/index.tsx @@ -5,42 +5,48 @@ import { TabsTrigger, } from "@renderer/components/ui/tabs" import { Recommendations } from "@renderer/components/subscribe/recommendations" -import { RSSForm } from "@renderer/components/subscribe/rss-form" -import { RSSHubForm } from "@renderer/components/subscribe/rsshub-form" -import { FollowUserForm } from "@renderer/components/subscribe/follow-user-form" +import { SubscribeForm } from "@renderer/components/subscribe/form" export function Component() { const tabs = [ + { + name: "General", + value: "general", + }, { name: "RSS", - content: , + value: "rss", }, { name: "RSSHub", - content: , + value: "rsshub", }, { name: "Follow User", - content: , + value: "user", }, { name: "RSS3", + value: "rss3", + disabled: true, }, { name: "Email", + value: "email", + disabled: true, }, ] return (
Subscribe
- + {tabs.map((tab) => ( {tab.name} @@ -48,8 +54,8 @@ export function Component() { {tabs.map((tab) => ( - {tab.content || Comming Soon} - {tab.content && } + + ))}