import { FormEvent, useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { ListPlus, Trash2 } from 'lucide-react' import toast from 'react-hot-toast' import { playbackAPI } from '../api/playback' import { confirmAction } from '../components/confirmAction' import type { Playlist } from '../types' // Landing page for playlists. Lists every playlist owned by the current // user and lets them create / delete one. export function PlaylistsPage() { const [items, setItems] = useState([]) const [name, setName] = useState('') const [loading, setLoading] = useState(true) const refresh = () => playbackAPI .listPlaylists() .then(setItems) .finally(() => setLoading(false)) useEffect(() => { refresh().catch(() => undefined) }, []) const onCreate = async (e: FormEvent) => { e.preventDefault() try { await playbackAPI.createPlaylist(name) toast.success('已创建') setName('') await refresh() } catch { toast.error('创建失败') } } return (

播放列表

setName(e.target.value)} />
{loading &&

加载中…

} {!loading && items.length === 0 &&

还没有任何播放列表。

}
{items.map((p) => (
{p.name} {p.is_public && ( public )}
))}
) }