import Link from 'next/link'; interface VideoData { id: string; title: string; uploader: string; thumbnail: string; view_count: number; duration: string; } interface Subscription { id: number; channel_id: string; channel_name: string; channel_avatar: string; } async function getHistory() { try { const res = await fetch('http://127.0.0.1:8080/api/history?limit=20', { cache: 'no-store' }); if (!res.ok) return []; return res.json() as Promise; } catch { return []; } } async function getSubscriptions() { try { const res = await fetch('http://127.0.0.1:8080/api/subscriptions', { cache: 'no-store' }); if (!res.ok) return []; return res.json() as Promise; } catch { return []; } } function formatViews(views: number): string { if (views >= 1000000) return (views / 1000000).toFixed(1) + 'M'; if (views >= 1000) return (views / 1000).toFixed(1) + 'K'; return views.toString(); } export default async function LibraryPage() { const [history, subscriptions] = await Promise.all([getHistory(), getSubscriptions()]); return (
{/* Subscriptions Section */} {subscriptions.length > 0 && (

Subscriptions

{subscriptions.map((sub) => (
{sub.channel_avatar || (sub.channel_name ? sub.channel_name[0].toUpperCase() : '?')}
{sub.channel_name || sub.channel_id} ))}
)} {/* Watch History Section */}

Watch History

{history.length === 0 ? (

No videos watched yet

Videos you watch will appear here

) : (
{history.map((video) => (
{video.title} {video.duration && (
{video.duration}
)}

{video.title}

{video.uploader}

{video.view_count > 0 && (

{formatViews(video.view_count)} views

)}
))}
)}
); }