| 1234567891011121314151617181920212223242526272829303132333435 |
- "use client";
- import { useMutation, useQueryClient } from "@tanstack/react-query";
- import { getSupabaseBrowserClient } from "@/lib/supabase/client";
- async function deleteMovie(movieId: string) {
- const res = await fetch(`/api/movies/${movieId}`, {
- method: "DELETE",
- });
- if (!res.ok) {
- const data = await res.json().catch(() => ({}));
- throw new Error(data.error || "Failed to delete movie");
- }
- return res.json();
- }
- export function useDeleteMovie(groupId: string) {
- const queryClient = useQueryClient();
- return useMutation({
- mutationFn: deleteMovie,
- onSuccess: async () => {
- void queryClient.invalidateQueries({ queryKey: ["group-movies", groupId] });
- const supabase = getSupabaseBrowserClient();
- const {
- data: { user },
- } = await supabase.auth.getUser();
- if (user) {
- void queryClient.invalidateQueries({ queryKey: ["all-user-movies", user.id] });
- }
- },
- });
- }
|