import { Link } from '@tanstack/react-router'; import { usePinnedLiveBlogs } from '@/queries/live-blogs'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import type { LiveBlog } from '@/lib/api'; import { Clock, MessageSquare, Eye, Pin, Play, Square, ChevronRight } from 'lucide-react'; interface PinnedLiveBlogSidebarProps { className?: string; maxItems?: number; } export function PinnedLiveBlogSidebar({ className = '', maxItems = 3 }: PinnedLiveBlogSidebarProps) { const { data: pinnedBlogs, isLoading, error } = usePinnedLiveBlogs(); if (isLoading) { return ( Pinned Live Blogs {[1, 2, 3].map((i) => ( ))} ); } if (isLoading) { return ( Live Coverage {[1, 2, 3].map((i) => ( ))} ); } if (error) { return ( Live Coverage Error loading live coverage ); } const displayBlogs = (pinnedBlogs || []).slice(0, maxItems); const getStatusColor = (status: string) => { switch (status) { case 'live': return 'bg-green-100 text-green-800 border-green-200'; case 'ended': return 'bg-red-100 text-red-800 border-red-200'; default: return 'bg-gray-100 text-gray-800 border-gray-200'; } }; const getStatusIcon = (status: string) => { switch (status) { case 'live': return ; case 'ended': return ; default: return null; } }; const formatTime = (dateString: string) => { const date = new Date(dateString); const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffMins = Math.floor(diffMs / 60000); if (diffMins < 60) { return `${diffMins}m ago`; } else if (diffMins < 1440) { return `${Math.floor(diffMins / 60)}h ago`; } else { return `${Math.floor(diffMins / 1440)}d ago`; } }; const getLatestUpdate = (blog: LiveBlog) => { if (!blog.updates || blog.updates.length === 0) return null; return blog.updates[blog.updates.length - 1]; }; return ( Live Coverage {(pinnedBlogs || []).length} pinned {displayBlogs.length === 0 ? ( No pinned live blogs at the moment Check back later for live coverage ) : ( <> {displayBlogs.map((blog) => { const latestUpdate = getLatestUpdate(blog); return ( {blog.title} {blog.description && ( {blog.description} )} {getStatusIcon(blog.status)} {blog.status} {/* Latest update preview */} {latestUpdate && ( {formatTime(latestUpdate.createdAt)} {latestUpdate.content} )} {/* Stats */} {blog.updates?.length || 0} updates {blog.viewCount} views ); })} {/* View all button */} {(pinnedBlogs || []).length > maxItems && ( View all pinned blogs )} > )} ); }
Error loading live coverage
No pinned live blogs at the moment
Check back later for live coverage
{blog.description}
{latestUpdate.content}