import Link from 'next/link'; interface VideoData { id: string; title: string; uploader: string; channel_id: string; thumbnail: string; view_count: number; duration: string; } interface Subscription { id: number; channel_id: string; channel_name: string; channel_avatar: string; } 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 []; } } async function getChannelVideos(channelId: string, limit: number = 5) { try { const res = await fetch(`http://127.0.0.1:8080/api/channel/videos?id=${channelId}&limit=${limit}`, { 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 SubscriptionsPage() { const subscriptions = await getSubscriptions(); if (subscriptions.length === 0) { return (

No subscriptions yet

Subscribe to channels to see their latest videos here

); } const videosPerChannel = await Promise.all( subscriptions.map(async (sub) => ({ subscription: sub, videos: await getChannelVideos(sub.channel_id, 5), })) ); return (

Subscriptions

{videosPerChannel.map(({ subscription, videos }) => (
{subscription.channel_name ? subscription.channel_name[0].toUpperCase() : '?'}

{subscription.channel_name || subscription.channel_id}

{videos.length > 0 ? (
{videos.map((video) => (
{video.title} {video.duration && (
{video.duration}
)}

{video.title}

{formatViews(video.view_count)} views

))}
) : (

No videos available

)}
))}
); }