From 3f418669f3867f1bd758621a321ccfdcd9ad781d Mon Sep 17 00:00:00 2001 From: Daniil Tsivinsky Date: Thu, 12 Mar 2026 22:42:22 +0300 Subject: [PATCH] add button to delete podcast & link to website --- web/src/api/podcasts.ts | 11 ++++++++++ web/src/pages/podcast.tsx | 44 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/web/src/api/podcasts.ts b/web/src/api/podcasts.ts index 9b3bd36..b46da02 100644 --- a/web/src/api/podcasts.ts +++ b/web/src/api/podcasts.ts @@ -47,3 +47,14 @@ export const useCreatePodcastMutation = () => { }, }); }; + +export const useDeletePodcastMutation = () => { + return useMutation({ + mutationFn: async ({ id }: { id: number }) => { + const resp = await fetch(`/api/podcasts/${id}`, { + method: "DELETE", + }); + return await resp.json(); + }, + }); +}; diff --git a/web/src/pages/podcast.tsx b/web/src/pages/podcast.tsx index a54307a..06ed229 100644 --- a/web/src/pages/podcast.tsx +++ b/web/src/pages/podcast.tsx @@ -1,5 +1,5 @@ import { useParams } from "react-router"; -import { usePodcastQuery } from "../api/podcasts"; +import { useDeletePodcastMutation, usePodcastQuery } from "../api/podcasts"; import { usePodcastEpisodesQuery, useUpdateEpisodeMutation, @@ -9,8 +9,10 @@ import { usePlayerContext } from "../player/context"; import { PlayIcon } from "../icons/play"; import { PauseIcon } from "../icons/pause"; import { useQueryClient } from "@tanstack/react-query"; +import { useNavigate } from "react-router"; export const PodcastPage = () => { + const navigate = useNavigate(); const queryClient = useQueryClient(); const { id } = useParams<{ id: string }>(); @@ -20,6 +22,29 @@ export const PodcastPage = () => { const player = usePlayerContext(); const updateEpisodeMutation = useUpdateEpisodeMutation(); + const deletePodcastMutation = useDeletePodcastMutation(); + + const handleDeletePodcast = () => { + if ( + !confirm( + "Are you sure you want to delete this podcast with all episodes?", + ) + ) + return; + if (typeof id === "undefined") return; + + deletePodcastMutation.mutate( + { + id: parseInt(id), + }, + { + onSuccess() { + queryClient.invalidateQueries({ queryKey: ["podcasts"] }); + navigate("/"); + }, + }, + ); + }; const handleMarkCompleted = (episodeId: number) => { updateEpisodeMutation.mutate( @@ -64,6 +89,23 @@ export const PodcastPage = () => {

{podcast?.name}

{podcast?.description}

+
+ + Website + + +