From 593b8506556c3b1d81d92151aaa59a6885144c3d Mon Sep 17 00:00:00 2001 From: Manoo07 Date: Sun, 8 Sep 2024 12:09:29 +0530 Subject: [PATCH] feat: add delete button to remove tracks from the queue --- app/api/streams/route.ts | 28 ++++++++++++++++++++++++++++ app/components/StreamView.tsx | 29 ++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/app/api/streams/route.ts b/app/api/streams/route.ts index 22b1d42..16ae27e 100644 --- a/app/api/streams/route.ts +++ b/app/api/streams/route.ts @@ -266,3 +266,31 @@ export async function GET(req: NextRequest) { isCreator, }); } + +export async function DELETE(req: NextRequest) { + try { + const { searchParams } = new URL(req.url); + const id = searchParams.get("id"); + + if (!id) { + return NextResponse.json({ error: "ID is required" }, { status: 400 }); + } + + await prismaClient.stream.delete({ + where: { id: id }, + }); + + return NextResponse.json( + { message: "Stream deleted successfully" }, + { status: 200 } + ); + } catch (error) { + console.error("Error deleting stream:", error); + return NextResponse.json( + { error: "Failed to delete stream" }, + { status: 500 } + ); + } finally { + await prismaClient.$disconnect(); + } +} diff --git a/app/components/StreamView.tsx b/app/components/StreamView.tsx index 380ee20..062c736 100644 --- a/app/components/StreamView.tsx +++ b/app/components/StreamView.tsx @@ -11,6 +11,7 @@ import { Trash2, X, Video, + Trash, } from "lucide-react"; import { toast, ToastContainer } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; @@ -31,6 +32,7 @@ import { } from "@/components/ui/dialog"; import { url } from "inspector"; import credentials from "next-auth/providers/credentials"; +import axios from "axios"; interface Video { id: string; @@ -134,6 +136,22 @@ export default function StreamView({ setInputLink(""); }; + const handleDelete = async (id: string) => { + try { + const response = await axios.delete(`/api/streams?id=${id}`); + + if (response.status === 200) { + toast.success("Stream deleted successfully!"); + console.log("Track removed successfully:", response.data); + } else { + toast.error("Failed to delete stream."); + console.error("Failed to remove track:", response.data); + } + } catch (error) { + toast.error("Error occurred while deleting stream."); + console.error("Error occurred while removing track:", error); + } + }; const handleVote = (id: string, isUpvote: boolean) => { setQueue( queue @@ -230,7 +248,7 @@ export default function StreamView({

{video.title}

-
+
+