add button to delete podcast & link to website
This commit is contained in:
@@ -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();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import { usePodcastQuery } from "../api/podcasts";
|
import { useDeletePodcastMutation, usePodcastQuery } from "../api/podcasts";
|
||||||
import {
|
import {
|
||||||
usePodcastEpisodesQuery,
|
usePodcastEpisodesQuery,
|
||||||
useUpdateEpisodeMutation,
|
useUpdateEpisodeMutation,
|
||||||
@@ -9,8 +9,10 @@ import { usePlayerContext } from "../player/context";
|
|||||||
import { PlayIcon } from "../icons/play";
|
import { PlayIcon } from "../icons/play";
|
||||||
import { PauseIcon } from "../icons/pause";
|
import { PauseIcon } from "../icons/pause";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
|
|
||||||
export const PodcastPage = () => {
|
export const PodcastPage = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
|
|
||||||
@@ -20,6 +22,29 @@ export const PodcastPage = () => {
|
|||||||
const player = usePlayerContext();
|
const player = usePlayerContext();
|
||||||
|
|
||||||
const updateEpisodeMutation = useUpdateEpisodeMutation();
|
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) => {
|
const handleMarkCompleted = (episodeId: number) => {
|
||||||
updateEpisodeMutation.mutate(
|
updateEpisodeMutation.mutate(
|
||||||
@@ -64,6 +89,23 @@ export const PodcastPage = () => {
|
|||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<h2 className="text-2xl font-semibold">{podcast?.name}</h2>
|
<h2 className="text-2xl font-semibold">{podcast?.name}</h2>
|
||||||
<p>{podcast?.description}</p>
|
<p>{podcast?.description}</p>
|
||||||
|
<div className="mt-auto flex items-center gap-2">
|
||||||
|
<a
|
||||||
|
href={podcast?.link}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="block bg-blue-500 text-white py-1 px-4 rounded"
|
||||||
|
>
|
||||||
|
Website
|
||||||
|
</a>
|
||||||
|
<button
|
||||||
|
className="bg-red-500 text-white py-1 px-4 rounded w-fit cursor-pointer"
|
||||||
|
disabled={deletePodcastMutation.isPending}
|
||||||
|
onClick={handleDeletePodcast}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user