import { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { Layout, Row, Col, Card, Typography, Tag, Button, Skeleton, Empty, Space, } from 'antd' import { LoginOutlined, FireOutlined, ClockCircleOutlined } from '@ant-design/icons' import { fetchStreams, type StreamInfo } from '../api/streams' const { Header, Content } = Layout const { Title, Text } = Typography const statusMeta: Record = { live: { color: 'red', label: '直播中', icon: }, pending: { color: 'blue', label: '待开播', icon: }, ended: { color: 'default', label: '已结束', icon: null }, cancelled: { color: 'default', label: '已取消', icon: null }, } export default function HomePage() { const [streams, setStreams] = useState([]) const [loading, setLoading] = useState(true) const navigate = useNavigate() useEffect(() => { fetchStreams() .then(setStreams) .catch(() => {}) .finally(() => setLoading(false)) }, []) const sorted = [...streams].sort((a, b) => { const order: Record = { live: 0, pending: 1, ended: 2, cancelled: 3 } return (order[a.status] ?? 9) - (order[b.status] ?? 9) }) return (
LiveStream <Text type="secondary" style={{ fontSize: 14, marginLeft: 10, fontWeight: 400 }}> 简易直播平台 </Text>
全部直播 {loading ? ( {[1,2,3,4,5,6].map((i) => ( ))} ) : sorted.length === 0 ? ( ) : ( {sorted.map((s) => { const meta = statusMeta[s.status] ?? statusMeta.pending return ( {!s.cover_url && ( {s.status === 'live' ? : '🎬'} )} } onClick={() => navigate(`/watch/${s.id}`)} > {meta.icon} {meta.label} {s.title} } description={ s.description ? {s.description} : 暂无简介 } /> ) })} )}
) }