'use client';
import React from 'react';
import Image from 'next/image';
import Link from 'next/link';
import {
Calendar,
Trophy,
Users,
Star,
Clock,
Flag,
ChevronRight,
Target,
Award,
Activity,
Play,
Medal,
Crown,
Heart,
UserPlus,
} from 'lucide-react';
import Card from '@/components/ui/Card';
import Button from '@/components/ui/Button';
import { useDashboardOverview } from '@/hooks/useDashboardService';
// Helper functions
function getCountryFlag(countryCode: string): string {
const code = countryCode.toUpperCase();
if (code.length === 2) {
const codePoints = [...code].map(char => 127397 + char.charCodeAt(0));
return String.fromCodePoint(...codePoints);
}
return '🏁';
}
function timeUntil(date: Date): string {
const now = new Date();
const diffMs = date.getTime() - now.getTime();
if (diffMs < 0) return 'Started';
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
const diffDays = Math.floor(diffHours / 24);
if (diffDays > 0) {
return `${diffDays}d ${diffHours % 24}h`;
}
if (diffHours > 0) {
const diffMinutes = Math.floor((diffMs % (1000 * 60 * 60)) / (1000 * 60));
return `${diffHours}h ${diffMinutes}m`;
}
const diffMinutes = Math.floor(diffMs / (1000 * 60));
return `${diffMinutes}m`;
}
function timeAgo(timestamp: Date | string): string {
const time = typeof timestamp === 'string' ? new Date(timestamp) : timestamp;
const diffMs = Date.now() - time.getTime();
const diffMinutes = Math.floor(diffMs / 60000);
if (diffMinutes < 1) return 'Just now';
if (diffMinutes < 60) return `${diffMinutes}m ago`;
const diffHours = Math.floor(diffMinutes / 60);
if (diffHours < 24) return `${diffHours}h ago`;
const diffDays = Math.floor(diffHours / 24);
return `${diffDays}d ago`;
}
function getGreeting(): string {
const hour = new Date().getHours();
if (hour < 12) return 'Good morning';
if (hour < 18) return 'Good afternoon';
return 'Good evening';
}
import { DashboardFeedItemSummaryViewModel } from '@/lib/view-models/DashboardOverviewViewModel';
export default function DashboardPage() {
const { data: dashboardData, isLoading, error } = useDashboardOverview();
if (isLoading) {
return (
{getGreeting()}, {wins} Wins {podiums} Podiums {consistency}% Consistency {activeLeaguesCount} Active Leagues {nextRace.car} Starts in {timeUntil(nextRace.scheduledAt)}
{leagueName}
{points} points • {totalDrivers} drivers
No activity yet Join leagues and add friends to see activity here {race.track} {race.car} No upcoming races {friend.name} {getCountryFlag(friend.country)} No friends yet
{currentDriver.name}
{getCountryFlag(currentDriver.country)}
{nextRace.track}
View all
View all
{friends.length} friends
{item.headline}
{item.body && ({item.body}
)}{timeAgo(item.timestamp)}