feat(rsshub): delete instance, close #2883
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { Button } from "@follow/components/ui/button/index.js"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
import { Queries } from "~/queries"
|
||||
|
||||
export const ConfirmDeleteModalContent = ({ id, dismiss }: { dismiss: () => void; id: string }) => {
|
||||
const { t } = useTranslation("settings")
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: () => {
|
||||
return apiClient.rsshub.$delete({ json: { id } })
|
||||
},
|
||||
onSuccess: () => {
|
||||
Queries.rsshub.list().invalidate()
|
||||
toast.success(t("rsshub.table.delete.success"))
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error.message)
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="w-[540px]">
|
||||
<div className="mb-4">
|
||||
<i className="i-mingcute-warning-fill -mb-1 mr-1 size-5 text-red-500" />
|
||||
{t("rsshub.table.delete.confirm")}
|
||||
</div>
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
className="bg-red-600"
|
||||
onClick={() => {
|
||||
deleteMutation.mutate()
|
||||
dismiss()
|
||||
}}
|
||||
>
|
||||
{t("rsshub.table.delete.label")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import { useAuthQuery } from "~/hooks/common"
|
||||
import { useSubViewTitle } from "~/modules/app-layout/subview/hooks"
|
||||
import { useTOTPModalWrapper } from "~/modules/profile/hooks"
|
||||
import { AddModalContent } from "~/modules/rsshub/add-modal-content"
|
||||
import { ConfirmDeleteModalContent } from "~/modules/rsshub/delete-modal-content"
|
||||
import { SetModalContent } from "~/modules/rsshub/set-modal-content"
|
||||
import { UserAvatar } from "~/modules/user/UserAvatar"
|
||||
import { Queries } from "~/queries"
|
||||
@@ -145,6 +146,10 @@ function List({ data }: { data?: RSSHubModel[] }) {
|
||||
return a.price - b.price || loadA - loadB
|
||||
})
|
||||
.map((instance) => {
|
||||
const instanceUserCountExceptOwner = instance.userCount
|
||||
? instance.userCount - (instance.ownerUserId === me?.id ? 1 : 0)
|
||||
: 0
|
||||
|
||||
return (
|
||||
<TableRow key={instance.id}>
|
||||
<TableCell className="text-nowrap">
|
||||
@@ -226,6 +231,22 @@ function List({ data }: { data?: RSSHubModel[] }) {
|
||||
{t("rsshub.table.edit")}
|
||||
</Button>
|
||||
)}
|
||||
{me?.id === instance.ownerUserId && (
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={!!instanceUserCountExceptOwner}
|
||||
onClick={() =>
|
||||
present({
|
||||
title: t("rsshub.table.delete.label"),
|
||||
content: ({ dismiss }) => (
|
||||
<ConfirmDeleteModalContent dismiss={dismiss} id={instance.id} />
|
||||
),
|
||||
})
|
||||
}
|
||||
>
|
||||
{t("rsshub.table.delete.label")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
@@ -379,6 +379,9 @@
|
||||
"rsshub.add_new_instance": "Add New Instance",
|
||||
"rsshub.description": "RSSHub is a community-driven open-source RSS network. Folo 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.delete.confirm": "Are you sure you want to delete this instance?",
|
||||
"rsshub.table.delete.label": "Delete",
|
||||
"rsshub.table.delete.success": "Instance deleted successfully.",
|
||||
"rsshub.table.description": "Description",
|
||||
"rsshub.table.edit": "Edit",
|
||||
"rsshub.table.inuse": "In Use",
|
||||
|
||||
Reference in New Issue
Block a user