"use client"; import Image from "next/image"; import { useEffect, useState } from "react"; import type { Session } from "next-auth"; import { getBadge } from "../../lib/badges"; function useDailyStats() { const [today, setToday] = useState(null); useEffect(() => { fetch("/api/stats") .then((r) => r.json()) .then((d) => setToday(d.total)) .catch(() => {}); }, []); return today; } function useUserWins(enabled: boolean) { const [wins, setWins] = useState(0); useEffect(() => { if (!enabled) return; fetch("/api/games") .then((r) => (r.ok ? r.json() : [])) .then((games: unknown) => { if (Array.isArray(games)) { setWins((games as { won: boolean }[]).filter((g) => g.won).length); } else { setWins(0); } }) .catch(() => setWins(0)); }, [enabled]); return wins; } type HomeScreenProps = { playerName: string; setPlayerName: (v: string) => void; joinCode: string; setJoinCode: (v: string) => void; error: string | null; setError: (v: string | null) => void; loading: boolean; onCreateRoom: () => void; onJoinRoom: () => void; onSolo: () => void; session: Session | null; onShowAuth: () => void; onShowProfile: () => void; onShowLeaderboard: () => void; onDaily: () => void; onBlitz: () => void; }; export function HomeScreen({ playerName, setPlayerName, joinCode, setJoinCode, error, setError, loading, onCreateRoom, onJoinRoom, onSolo, session, onShowAuth, onShowProfile, onShowLeaderboard, onDaily, onBlitz, }: HomeScreenProps) { const btnGhost = "min-h-9 px-3 rounded-lg text-xs sm:text-sm font-semibold bg-[#242424] border border-[#2e2e2e] text-[#f0f0f0] hover:bg-[#1a1a1a] cursor-pointer whitespace-nowrap"; const today = useDailyStats(); const wins = useUserWins(!!session?.user); const badge = session?.user ? getBadge(wins) : null; return (
{/* Topbar */}
{session?.user ? ( ) : ( )}
{/* Hero */}
WikiRush

Navigue entre les articles Wikipedia pour atteindre la cible en premier !

{today !== null && (

{today.toLocaleString("fr-FR")} {" "} partie{today > 1 ? "s" : ""} jouée{today > 1 ? "s" : ""} au total

)} {badge && (
{/* eslint-disable-next-line @next/next/no-img-element */} {badge.name} {badge.name}
)}
{/* Form */}
{error && (
{error}
)} setPlayerName(e.target.value)} maxLength={20} onKeyDown={(e) => e.key === "Enter" && onCreateRoom()} /> {/* Multijoueur */}

Multijoueur

{/* Join row - colonne sur mobile, ligne sur sm+ */}
setJoinCode(e.target.value.toUpperCase().slice(0, 4)) } maxLength={4} onKeyDown={(e) => e.key === "Enter" && onJoinRoom()} />
{/* Divider */}
ou
{/* Solo */}

Solo

); }