feat: category rename dialog
This commit is contained in:
@@ -11,17 +11,20 @@ import { useToast } from "@renderer/components/ui/use-toast"
|
||||
import { ToastAction } from "@renderer/components/ui/toast"
|
||||
import { apiFetch } from "@renderer/lib/queries/api-fetch"
|
||||
import { Dialog, DialogTrigger } from "@renderer/components/ui/dialog"
|
||||
import { CategoryRenameDialog } from "./category-rename-dialog"
|
||||
|
||||
export function CategoryContextMenu({
|
||||
name,
|
||||
view,
|
||||
children,
|
||||
onOpenChange,
|
||||
feedIdList,
|
||||
}: {
|
||||
name: string
|
||||
view?: number
|
||||
children: React.ReactNode
|
||||
onOpenChange?: (open: boolean) => void
|
||||
feedIdList: string[]
|
||||
}) {
|
||||
const [dialogOpen, setDialogOpen] = useState(false)
|
||||
const { toast } = useToast()
|
||||
@@ -41,6 +44,12 @@ export function CategoryContextMenu({
|
||||
<ContextMenuItem>Unfollow All</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
<CategoryRenameDialog
|
||||
feedIdList={feedIdList}
|
||||
view={view}
|
||||
category={name}
|
||||
onSuccess={() => setDialogOpen(false)}
|
||||
/>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { z } from "zod"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useForm } from "react-hook-form"
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
FormDescription,
|
||||
} from "@renderer/components/ui/form"
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
||||
import {
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@renderer/components/ui/dialog"
|
||||
import { Button } from "@renderer/components/ui/button"
|
||||
import { apiFetch } from "@renderer/lib/queries/api-fetch"
|
||||
import { Input } from "@renderer/components/ui/input"
|
||||
|
||||
const formSchema = z.object({
|
||||
category: z.string(),
|
||||
})
|
||||
|
||||
export function CategoryRenameDialog({
|
||||
feedIdList,
|
||||
onSuccess,
|
||||
category,
|
||||
view,
|
||||
}: {
|
||||
feedIdList: string[]
|
||||
onSuccess?: () => void
|
||||
category: string
|
||||
view?: number
|
||||
}) {
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
category,
|
||||
},
|
||||
})
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const renameMutation = useMutation({
|
||||
mutationFn: async (values: z.infer<typeof formSchema>) =>
|
||||
apiFetch("/categories", {
|
||||
method: "PATCH",
|
||||
body: {
|
||||
feedIdList,
|
||||
category: values.category,
|
||||
},
|
||||
}),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["subscriptions", view],
|
||||
})
|
||||
onSuccess?.()
|
||||
},
|
||||
})
|
||||
|
||||
function onSubmit(values: z.infer<typeof formSchema>) {
|
||||
console.log("onSubmit", values)
|
||||
renameMutation.mutate(values)
|
||||
}
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Rename Category</DialogTitle>
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="category"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<Button type="submit" isLoading={renameMutation.isPending}>
|
||||
Rename
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
)
|
||||
}
|
||||
@@ -140,6 +140,7 @@ function FeedCategory({
|
||||
name={data.name}
|
||||
view={view}
|
||||
onOpenChange={() => setCatrgoryActive()}
|
||||
feedIdList={data.list.map((feed) => feed.feedId)}
|
||||
>
|
||||
<div className="flex items-center min-w-0 w-full">
|
||||
<CollapsibleTrigger
|
||||
|
||||
Reference in New Issue
Block a user