import { FormEvent, useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { ChevronRight, ListMusic, ListPlus, Trash2 } from 'lucide-react' import toast from 'react-hot-toast' import { playbackAPI } from '../api/playback' import { confirmAction } from '../components/confirmAction' import { PageHeader } from '../components/PageHeader' import type { Playlist } from '../types' export function PlaylistsPage() { const [items, setItems] = useState([]) const [name, setName] = useState('') const [loading, setLoading] = useState(true) const [creating, setCreating] = useState(false) const refresh = () => playbackAPI .listPlaylists() .then(setItems) .finally(() => setLoading(false)) useEffect(() => { refresh().catch(() => undefined) }, []) const onCreate = async (e: FormEvent) => { e.preventDefault() const trimmed = name.trim() if (!trimmed) return setCreating(true) try { await playbackAPI.createPlaylist(trimmed) toast.success('已创建') setName('') await refresh() } catch { toast.error('创建失败') } finally { setCreating(false) } } const isEmpty = !loading && items.length === 0 return (
setName(e.target.value)} disabled={creating} />
{loading && (
加载中…
)} {isEmpty && (

还没有任何播放列表

在上方输入名称创建列表,或在媒体详情页点击「加入播放列表」

)} {items.length > 0 && (
{items.map((p) => (

{p.name}

{p.is_public && ( 公开 )}
))}
)}
) }