From 47ded5ed9f946a44dfac0c3f37a6e4aa69e14b01 Mon Sep 17 00:00:00 2001 From: choi Date: Thu, 16 Jan 2025 15:11:29 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8A=B8=EB=9E=99=20=EC=88=98=EC=A0=95,=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20&=20=ED=8A=B8=EB=9E=99=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/albums/[id]/page.tsx | 1 + src/app/layout.tsx | 2 + src/app/page.tsx | 10 +- src/components/albums/EditTrackModal.tsx | 138 +++++++++++++++++++++ src/components/albums/TrackActions.tsx | 133 ++++++++++++++++++++ src/components/albums/TrackList.tsx | 34 +++++- src/components/home/TrackSection.tsx | 148 +++++++++++++++++++++++ 7 files changed, 454 insertions(+), 12 deletions(-) create mode 100644 src/components/albums/EditTrackModal.tsx create mode 100644 src/components/albums/TrackActions.tsx create mode 100644 src/components/home/TrackSection.tsx diff --git a/src/app/albums/[id]/page.tsx b/src/app/albums/[id]/page.tsx index 623bd48..9fc81be 100644 --- a/src/app/albums/[id]/page.tsx +++ b/src/app/albums/[id]/page.tsx @@ -49,6 +49,7 @@ export default async function AlbumPage({ params }: AlbumPageProps) { diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 4720d1e..93d2bff 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -7,6 +7,7 @@ import { BackgroundImage } from "@/components/layout/BackgroundImage"; import { getAuthCookie } from "@/lib/server-auth"; import { ThemeProvider } from "@/contexts/theme/ThemeContext"; import { UserProvider } from "@/contexts/auth/UserContext"; +import { Toaster } from "@/components/ui/toaster" // getUser 함수 수정 const getUser = async () => { @@ -77,6 +78,7 @@ export default async function RootLayout({ + ); diff --git a/src/app/page.tsx b/src/app/page.tsx index f4ff694..e10dc0e 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,5 +1,6 @@ import { cn } from "@/lib/utils"; import { AlbumSection } from "@/components/home/AlbumSection"; +import { TrackSection } from "@/components/home/TrackSection"; export default function Home() { return ( @@ -18,14 +19,7 @@ export default function Home() { )} > - - {/* 최신 업로드 섹션 */} -
-

최신 업로드

-
- {/* 트랙 리스트가 들어갈 자리 */} -
-
+ diff --git a/src/components/albums/EditTrackModal.tsx b/src/components/albums/EditTrackModal.tsx new file mode 100644 index 0000000..8a35e64 --- /dev/null +++ b/src/components/albums/EditTrackModal.tsx @@ -0,0 +1,138 @@ +"use client"; + +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Textarea } from "@/components/ui/textarea"; +import { useState } from "react"; +import { useToast } from "@/hooks/use-toast"; +import { checkAuth } from "@/lib/auth"; + +interface Track { + uuid: string; + title: string; + lyric: string; +} + +interface EditTrackModalProps { + track: Track; + isOpen: boolean; + onClose: () => void; + onUpdate: (track: Track) => void; +} + +export function EditTrackModal({ track, isOpen, onClose, onUpdate }: EditTrackModalProps) { + const { toast } = useToast(); + const [isSubmitting, setIsSubmitting] = useState(false); + const [form, setForm] = useState({ + title: track.title, + lyric: track.lyric, + }); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + try { + setIsSubmitting(true); + const { accessToken } = await checkAuth(); + + const response = await fetch( + `${process.env.NEXT_PUBLIC_API_BASE_URL}/tracks/${track.uuid}`, + { + method: "PATCH", + headers: { + "Authorization": `Bearer ${accessToken}`, + "Content-Type": "application/json", + }, + credentials: "include", + body: JSON.stringify({ + title: form.title.trim(), + lyric: form.lyric.trim(), + }), + } + ); + + if (!response.ok) throw new Error("트랙 수정에 실패했습니다."); + + const updatedTrack = { ...track, ...form }; + onUpdate(updatedTrack); + + toast({ + title: "트랙 수정 완료", + description: "트랙이 수정되었습니다.", + variant: "default", + }); + + onClose(); + } catch (error) { + toast({ + variant: "destructive", + title: "트랙 수정 실패", + description: error instanceof Error ? error.message : "트랙 수정에 실패했습니다.", + }); + } finally { + setIsSubmitting(false); + } + }; + + return ( + + + + 트랙 수정 + 트랙 정보를 수정해주세요. + + +
+
+ + + setForm((prev) => ({ ...prev, title: e.target.value })) + } + className="bg-white/5 border-white/10" + maxLength={50} + required + disabled={isSubmitting} + /> +
+ +
+ +