'use client' import { PlaylistCard } from '@/components/PlaylistCard' import { CreatePlaylistModal, CreatePlaylistData } from '@/components/CreatePlaylistModal' import { useState, useEffect } from 'react' export default function PlaylistsPage() { const [playlists, setPlaylists] = useState([]) const [isModalOpen, setIsModalOpen] = useState(false) const [isCreating, setIsCreating] = useState(false) const [loading, setLoading] = useState(true) useEffect(() => { fetchPlaylists() }, []) const fetchPlaylists = async () => { try { const res = await fetch('/api/playlists') if (res.ok) { const data = await res.json() setPlaylists(data.playlists || []) } } catch (error) { console.error('Failed to fetch playlists:', error) } finally { setLoading(false) } } const handleCreatePlaylist = async (data: CreatePlaylistData) => { setIsCreating(true) try { const res = await fetch('/api/playlists', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: data.title, description: data.description, isPublic: data.isPublic, }), }) if (res.ok) { const result = await res.json() setPlaylists([result.playlist, ...playlists]) setIsModalOpen(false) } } catch (error) { console.error('Failed to create playlist:', error) } finally { setIsCreating(false) } } return (
{/* Header */}

My Playlists

Create and manage your music collections

{/* Playlists Grid */} {loading ? (

Loading playlists...

) : playlists.length > 0 ? (
{playlists.map((playlist) => ( ))}
) : (

You don't have any playlists yet

Create your first playlist to start organizing your music

)}
{/* Create Playlist Modal */} setIsModalOpen(false)} onSubmit={handleCreatePlaylist} isLoading={isCreating} />
) }