"use client" import { useEffect, useState } from "react" import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from "@/components/ui/card" import { ListMusic, Plus, PlayCircle, MoreHorizontal } from "lucide-react" import Link from "next/link" import { Button } from "@/components/ui/button" import { getApiUrl } from "@/lib/api-config" import { Skeleton } from "@/components/ui/skeleton" import { Playlist } from "@/types/models" export function UserPlaylistsList({ userId, isOwner = false }: { userId: number, isOwner?: boolean }) { const [playlists, setPlaylists] = useState([]) const [loading, setLoading] = useState(true) useEffect(() => { const token = localStorage.getItem("token") if (!token) return // If isOwner, use /mine endpoint to see private playlists too const endpoint = isOwner ? `${getApiUrl()}/playlists/mine` : `${getApiUrl()}/playlists?user_id=${userId}` fetch(endpoint, { headers: { Authorization: `Bearer ${token}` } }) .then(res => res.json()) .then(data => setPlaylists(data)) .catch(err => console.error(err)) .finally(() => setLoading(false)) }, [userId, isOwner]) if (loading) { return (
{[1, 2, 3].map(i => ( ))}
) } if (playlists.length === 0) { return (

No playlists created yet

{isOwner && ( )}
) } return (
{isOwner && (
)}
{playlists.map((playlist) => (
{!playlist.is_public && ( Private )}
{playlist.name} {playlist.description || "No description"}
{playlist.performance_count} tracks Updated {new Date(playlist.created_at).toLocaleDateString()}
))}
) }