From fc8eb55802fec2373e00d2eace2d70e7dcf00ab9 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 13 May 2024 13:14:53 +0800 Subject: [PATCH] feat: subsctiption deletion api --- .../src/components/feed-column/list.tsx | 34 ++++++++++++++++++- src/renderer/src/lib/queries/subscriptions.ts | 10 ------ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/renderer/src/components/feed-column/list.tsx b/src/renderer/src/components/feed-column/list.tsx index 2863614b4..1e9c81407 100644 --- a/src/renderer/src/components/feed-column/list.tsx +++ b/src/renderer/src/components/feed-column/list.tsx @@ -17,6 +17,8 @@ import { ContextMenuTrigger, ContextMenuSeparator, } from "@renderer/components/ui/context-menu" +import { useMutation, useQueryClient } from "@tanstack/react-query" +import { getCsrfToken } from "@hono/auth-js/react" export function FeedList({ className, @@ -85,6 +87,32 @@ function FeedCategory({ }) { const [open, setOpen] = useState(false) + const queryClient = useQueryClient() + const deleteMutation = useMutation({ + mutationFn: async (feedId: string) => { + return ( + await ( + await fetch(`${import.meta.env.VITE_API_URL}/subscriptions`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + credentials: "include", + body: JSON.stringify({ + feedId, + csrfToken: await getCsrfToken(), + }), + }) + ).json() + ).data + }, + onSuccess: () => { + queryClient.invalidateQueries({ + queryKey: ["subscriptions", view], + }) + }, + }) + return ( e.stopPropagation()}> Edit - Unfollow + deleteMutation.mutate(feed.feedId)} + > + Unfollow + Open Feed in Browser Open Site in Browser diff --git a/src/renderer/src/lib/queries/subscriptions.ts b/src/renderer/src/lib/queries/subscriptions.ts index ff1f5831a..c110dcdee 100644 --- a/src/renderer/src/lib/queries/subscriptions.ts +++ b/src/renderer/src/lib/queries/subscriptions.ts @@ -25,16 +25,6 @@ export const useSubscriptions = (view?: number) => ) ).json() ).data as SubscriptionResponse - // const counters = await ( - // await fetch( - // `${import.meta.env.VITE_MINIFLUX_ENDPOINT}/v1/feeds/counters`, - // { - // headers: { - // "X-Auth-Token": import.meta.env.VITE_MINIFLUX_TOKEN, - // }, - // }, - // ) - // ).json() const categories = { list: {},