blob: 5e585a940ce467cc56a89d138261d036d14aafb5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
"use client"
import { useMutation, useQueryClient } from "@tanstack/react-query"
import { createSupabaseBrowserClient } from "@/lib/supabase/client"
import { queryKeys } from "./query-keys"
import { notify } from "@/lib/notify"
export function useSubscribeToFeed() {
const supabaseClient = createSupabaseBrowserClient()
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (parameters: {
feedUrl: string
folderIdentifier?: string | null
customTitle?: string | null
}) => {
const { data, error } = await supabaseClient.rpc("subscribe_to_feed", {
feed_url: parameters.feedUrl,
target_folder_id: parameters.folderIdentifier ?? undefined,
feed_custom_title: parameters.customTitle ?? undefined,
})
if (error) throw error
return data
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: queryKeys.subscriptions.all })
queryClient.invalidateQueries({ queryKey: queryKeys.timeline.all })
notify("feed added successfully")
},
onError: (error: Error) => {
notify("failed to add feed: " + error.message)
},
})
}
|