feat: rsshub add modal content
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import { Button } from "@follow/components/ui/button/index.js"
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@follow/components/ui/form/index.jsx"
|
||||
import { Input } from "@follow/components/ui/input/Input.js"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useEffect } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { z } from "zod"
|
||||
|
||||
import { whoami } from "~/atoms/user"
|
||||
import { ShikiHighLighter } from "~/components/ui/code-highlighter"
|
||||
import { useShikiDefaultTheme } from "~/components/ui/code-highlighter/shiki/hooks"
|
||||
import { useAddRSSHubMutation } from "~/queries/rsshub"
|
||||
|
||||
export function AddModalContent({ dismiss }: { dismiss: () => void }) {
|
||||
const { t } = useTranslation("settings")
|
||||
const addRSSHubMutation = useAddRSSHubMutation()
|
||||
const shikiTheme = useShikiDefaultTheme()
|
||||
const me = whoami()
|
||||
|
||||
const formSchema = z.object({
|
||||
baseUrl: z.string().url(),
|
||||
accessKey: z.string().optional(),
|
||||
})
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
})
|
||||
|
||||
const onSubmit = (data: z.infer<typeof formSchema>) => {
|
||||
addRSSHubMutation.mutate(data)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (addRSSHubMutation.isSuccess) {
|
||||
dismiss()
|
||||
}
|
||||
}, [addRSSHubMutation.isSuccess])
|
||||
|
||||
return (
|
||||
<div className="max-w-[550px] space-y-4 lg:min-w-[550px]">
|
||||
<div className="text-sm">{t("rsshub.addModal.description")}</div>
|
||||
|
||||
<ShikiHighLighter
|
||||
transparent
|
||||
theme={shikiTheme}
|
||||
className="group relative mt-3 cursor-auto select-text whitespace-pre break-words rounded-lg border border-border bg-zinc-100 p-2 text-sm dark:bg-neutral-800 [&_pre]:whitespace-pre [&_pre]:break-words [&_pre]:!p-0"
|
||||
code={`FOLLOW_OWNER_USER_ID=${me?.handle || me?.id} # User id or handle of your follow account
|
||||
FOLLOW_DESCRIPTION=${me?.name}'s instance # The description of your instance
|
||||
FOLLOW_PRICE=0 # The monthly price of your instance, set to 0 means free.
|
||||
FOLLOW_USER_LIMIT=1000 # The user limit of your instance, set it to 0 or 1 can make your instance private, leaving it empty means no restriction`}
|
||||
language="dotenv"
|
||||
/>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="baseUrl"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>{t("rsshub.addModal.base_url_label")}</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="https://" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="accessKey"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>{t("rsshub.addModal.access_key_label")}</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="flex items-center justify-end">
|
||||
<Button type="submit" isLoading={addRSSHubMutation.isPending}>
|
||||
{t("rsshub.addModal.add")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
import { Button } from "@follow/components/ui/button/index.js"
|
||||
import { Card, CardContent } from "@follow/components/ui/card/index.js"
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@follow/components/ui/form/index.jsx"
|
||||
import { Input } from "@follow/components/ui/input/Input.js"
|
||||
import type { RSSHubModel } from "@follow/models"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useEffect } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { z } from "zod"
|
||||
|
||||
import { whoami } from "~/atoms/user"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { UserAvatar } from "~/modules/user/UserAvatar"
|
||||
import { Queries } from "~/queries"
|
||||
import { useSetRSSHubMutation } from "~/queries/rsshub"
|
||||
|
||||
export function SetModalContent({
|
||||
dismiss,
|
||||
instance,
|
||||
}: {
|
||||
dismiss: () => void
|
||||
instance: RSSHubModel
|
||||
}) {
|
||||
const { t } = useTranslation("settings")
|
||||
const setRSSHubMutation = useSetRSSHubMutation()
|
||||
const details = useAuthQuery(Queries.rsshub.get({ id: instance.id }))
|
||||
const hasPurchase = !!details.data?.purchase
|
||||
const price = instance.ownerUserId === whoami()?.id ? 0 : instance.price
|
||||
|
||||
const formSchema = z.object({
|
||||
months: z.coerce
|
||||
.number()
|
||||
.min(hasPurchase ? 0 : 1)
|
||||
.max(12),
|
||||
})
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
months: hasPurchase ? 0 : 1,
|
||||
},
|
||||
})
|
||||
|
||||
const months = form.watch("months")
|
||||
|
||||
const onSubmit = (data: z.infer<typeof formSchema>) => {
|
||||
setRSSHubMutation.mutate({ id: instance.id, durationInMonths: data.months })
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (setRSSHubMutation.isSuccess) {
|
||||
dismiss()
|
||||
}
|
||||
}, [setRSSHubMutation.isSuccess])
|
||||
|
||||
return (
|
||||
<div className="max-w-[550px] space-y-4 lg:min-w-[550px]">
|
||||
<Card>
|
||||
<CardContent className="max-w-2xl space-y-2 p-6">
|
||||
<div className="mb-3 text-lg font-medium">{t("rsshub.useModal.about")}</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.table.owner")}</div>
|
||||
<UserAvatar
|
||||
userId={instance.ownerUserId}
|
||||
className="h-auto justify-start p-0"
|
||||
avatarClassName="size-6"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.table.description")}</div>
|
||||
<div className="line-clamp-2">{instance.description}</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.table.price")}</div>
|
||||
<div className="line-clamp-2 flex items-center gap-1">
|
||||
{instance.price} <i className="i-mgc-power text-accent" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.table.userCount")}</div>
|
||||
<div className="line-clamp-2">{instance.userCount}</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.table.userLimit")}</div>
|
||||
<div className="line-clamp-2">{instance.userLimit || t("rsshub.table.unlimited")}</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{details.data?.purchase && (
|
||||
<div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{t("rsshub.useModal.purchase_expires_at")}
|
||||
</div>
|
||||
<div className="line-clamp-2">
|
||||
{new Date(details.data.purchase.expiresAt).toLocaleString()}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||
{price > 0 && (
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="months"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>{t("rsshub.useModal.months_label")}</FormLabel>
|
||||
<FormControl>
|
||||
<div className="flex items-center gap-10">
|
||||
<div className="space-x-2">
|
||||
<Input className="w-24" type="number" max={12} {...field} />
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t("rsshub.useModal.month")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
{price * field.value}
|
||||
<i className="i-mgc-power text-accent" />
|
||||
</div>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<div className="flex items-center justify-end">
|
||||
<Button type="submit" isLoading={setRSSHubMutation.isPending}>
|
||||
{price
|
||||
? t("rsshub.useModal.useWith", {
|
||||
amount: price * months,
|
||||
})
|
||||
: t("rsshub.table.use")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,15 +1,5 @@
|
||||
import { Logo } from "@follow/components/icons/logo.jsx"
|
||||
import { Button } from "@follow/components/ui/button/index.js"
|
||||
import { Card, CardContent } from "@follow/components/ui/card/index.js"
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@follow/components/ui/form/index.jsx"
|
||||
import { Input } from "@follow/components/ui/input/Input.js"
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -19,30 +9,43 @@ import {
|
||||
TableRow,
|
||||
} from "@follow/components/ui/table/index.jsx"
|
||||
import type { RSSHubModel } from "@follow/models"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useEffect } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { z } from "zod"
|
||||
|
||||
import { whoami } from "~/atoms/user"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { useSubViewTitle } from "~/modules/app-layout/subview/hooks"
|
||||
import { AddModalContent } from "~/modules/rsshub/add-modal-content"
|
||||
import { SetModalContent } from "~/modules/rsshub/set-modal-content"
|
||||
import { UserAvatar } from "~/modules/user/UserAvatar"
|
||||
import { Queries } from "~/queries"
|
||||
import { useSetRSSHubMutation } from "~/queries/rsshub"
|
||||
|
||||
export function Component() {
|
||||
const { t } = useTranslation("settings")
|
||||
const { present } = useModalStack()
|
||||
|
||||
useSubViewTitle("words.rsshub")
|
||||
|
||||
const list = useAuthQuery(Queries.rsshub.list())
|
||||
|
||||
return (
|
||||
<div className="relative flex w-full flex-col items-center gap-8 px-4 pb-8 lg:pb-4">
|
||||
<div className="relative flex w-full max-w-4xl flex-col items-center gap-8 px-4 pb-8 lg:pb-4">
|
||||
<div className="pt-12 text-2xl font-bold">{t("words.rsshub", { ns: "common" })}</div>
|
||||
<div className="text-sm">{t("rsshub.description")}</div>
|
||||
<Button
|
||||
onClick={() =>
|
||||
present({
|
||||
title: t("rsshub.add_new_instance"),
|
||||
content: ({ dismiss }) => <AddModalContent dismiss={dismiss} />,
|
||||
})
|
||||
}
|
||||
>
|
||||
<div className="flex items-center gap-1">
|
||||
<i className="i-mgc-add-cute-re mr-1 text-base" />
|
||||
<span>{t("rsshub.add_new_instance")}</span>
|
||||
</div>
|
||||
</Button>
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.public_instances")}</div>
|
||||
<List data={list?.data} />
|
||||
</div>
|
||||
@@ -57,7 +60,7 @@ function List({ data }: { data?: RSSHubModel[] }) {
|
||||
const { present } = useModalStack()
|
||||
|
||||
return (
|
||||
<Table containerClassName="mt-2 max-w-4xl">
|
||||
<Table containerClassName="mt-2">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="font-bold" size="sm" />
|
||||
@@ -173,121 +176,3 @@ function List({ data }: { data?: RSSHubModel[] }) {
|
||||
</Table>
|
||||
)
|
||||
}
|
||||
|
||||
const SetModalContent = ({ dismiss, instance }: { dismiss: () => void; instance: RSSHubModel }) => {
|
||||
const { t } = useTranslation("settings")
|
||||
const setRSSHubMutation = useSetRSSHubMutation()
|
||||
const details = useAuthQuery(Queries.rsshub.get({ id: instance.id }))
|
||||
const hasPurchase = !!details.data?.purchase
|
||||
|
||||
const formSchema = z.object({
|
||||
months: z.coerce
|
||||
.number()
|
||||
.min(hasPurchase ? 0 : 1)
|
||||
.max(12),
|
||||
})
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
months: hasPurchase ? 0 : 1,
|
||||
},
|
||||
})
|
||||
|
||||
const months = form.watch("months")
|
||||
|
||||
const onSubmit = (data: z.infer<typeof formSchema>) => {
|
||||
setRSSHubMutation.mutate({ id: instance.id, durationInMonths: data.months })
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (setRSSHubMutation.isSuccess) {
|
||||
dismiss()
|
||||
}
|
||||
}, [setRSSHubMutation.isSuccess])
|
||||
|
||||
return (
|
||||
<div className="max-w-[550px] space-y-4 lg:min-w-[550px]">
|
||||
<Card>
|
||||
<CardContent className="max-w-2xl space-y-2 p-6">
|
||||
<div className="mb-3 text-lg font-medium">{t("rsshub.useModal.about")}</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.table.owner")}</div>
|
||||
<UserAvatar
|
||||
userId={instance.ownerUserId}
|
||||
className="h-auto justify-start p-0"
|
||||
avatarClassName="size-6"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.table.description")}</div>
|
||||
<div className="line-clamp-2">{instance.description}</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.table.price")}</div>
|
||||
<div className="line-clamp-2 flex items-center gap-1">
|
||||
{instance.price} <i className="i-mgc-power text-accent" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.table.userCount")}</div>
|
||||
<div className="line-clamp-2">{instance.userCount}</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-sm text-muted-foreground">{t("rsshub.table.userLimit")}</div>
|
||||
<div className="line-clamp-2">{instance.userLimit || t("rsshub.table.unlimited")}</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{details.data?.purchase && (
|
||||
<div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{t("rsshub.useModal.purchase_expires_at")}
|
||||
</div>
|
||||
<div className="line-clamp-2">
|
||||
{new Date(details.data.purchase.expiresAt).toLocaleString()}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||
{instance.price > 0 && (
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="months"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>{t("rsshub.useModal.months_label")}</FormLabel>
|
||||
<FormControl>
|
||||
<div className="flex items-center gap-10">
|
||||
<div className="space-x-2">
|
||||
<Input className="w-24" type="number" max={12} {...field} />
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t("rsshub.useModal.month")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
{instance.price * field.value}
|
||||
<i className="i-mgc-power text-accent" />
|
||||
</div>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<div className="flex items-center justify-end">
|
||||
<Button type="submit" isLoading={setRSSHubMutation.isPending}>
|
||||
{instance.price
|
||||
? t("rsshub.useModal.useWith", {
|
||||
amount: instance.price * months,
|
||||
})
|
||||
: t("rsshub.table.use")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export const useSetRSSHubMutation = ({ onError }: MutationBaseProps = {}) =>
|
||||
|
||||
export const useAddRSSHubMutation = ({ onError }: MutationBaseProps = {}) =>
|
||||
useMutation({
|
||||
mutationFn: ({ baseUrl, accessKey }: { baseUrl: string; accessKey: string }) =>
|
||||
mutationFn: ({ baseUrl, accessKey }: { baseUrl: string; accessKey?: string }) =>
|
||||
apiClient.rsshub.$post({
|
||||
json: {
|
||||
baseUrl,
|
||||
@@ -35,6 +35,11 @@ export const useAddRSSHubMutation = ({ onError }: MutationBaseProps = {}) =>
|
||||
},
|
||||
}),
|
||||
|
||||
onSuccess: (_) => {
|
||||
rsshub.list().invalidate()
|
||||
rsshub.status().invalidate()
|
||||
},
|
||||
|
||||
onError: (error) => {
|
||||
onError?.(error)
|
||||
},
|
||||
|
||||
@@ -284,7 +284,13 @@
|
||||
"profile.title": "Profile Settings",
|
||||
"profile.updateSuccess": "Profile updated.",
|
||||
"profile.update_password_success": "Password updated.",
|
||||
"rsshub.public_instances": "Instances",
|
||||
"rsshub.addModal.access_key_label": "Access Key (Optional)",
|
||||
"rsshub.addModal.add": "Add",
|
||||
"rsshub.addModal.base_url_label": "Base URL",
|
||||
"rsshub.addModal.description": "To use your own instance in Follow, you must add the following environment variables to it.",
|
||||
"rsshub.add_new_instance": "Add New Instance",
|
||||
"rsshub.description": "RSSHub is a community-driven open-source RSS network. Follow provides a built-in dedicated instance and uses it to support thousands of subscription contents, you can also achieve more stable content acquisition by using your own or third-party instances.",
|
||||
"rsshub.public_instances": "Available Instances",
|
||||
"rsshub.table.description": "Description",
|
||||
"rsshub.table.edit": "Edit",
|
||||
"rsshub.table.inuse": "In Use",
|
||||
|
||||
Reference in New Issue
Block a user