2026-04-10 15:43:07 +02:00
|
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
|
|
import { useEffect, useRef } from "react";
|
|
|
|
|
|
import { ArticleView } from "./ArticleView";
|
|
|
|
|
|
import { Breadcrumbs } from "./Breadcrumbs";
|
2026-04-10 22:57:31 +02:00
|
|
|
|
import { ShareBar } from "./ShareBar";
|
2026-04-10 15:43:07 +02:00
|
|
|
|
import type { Puzzle } from "../../lib/types";
|
|
|
|
|
|
|
|
|
|
|
|
type SoloPhase = "setup" | "playing" | "won";
|
|
|
|
|
|
|
|
|
|
|
|
type SoloScreenProps = {
|
|
|
|
|
|
phase: SoloPhase;
|
|
|
|
|
|
puzzle: Puzzle | null;
|
|
|
|
|
|
html: string;
|
|
|
|
|
|
title: string;
|
|
|
|
|
|
loading: boolean;
|
|
|
|
|
|
loadError: string | null;
|
|
|
|
|
|
history: string[];
|
|
|
|
|
|
clicks: number;
|
|
|
|
|
|
elapsedDisplay: string;
|
|
|
|
|
|
canGoBack: boolean;
|
|
|
|
|
|
onStart: () => void;
|
|
|
|
|
|
onNavigate: (title: string) => void;
|
|
|
|
|
|
onBack: () => void;
|
|
|
|
|
|
onQuit: () => void;
|
|
|
|
|
|
onNewGame: () => void;
|
|
|
|
|
|
onRetry: () => void;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export function SoloScreen({
|
|
|
|
|
|
phase, puzzle, html, title, loading, loadError, history, clicks,
|
|
|
|
|
|
elapsedDisplay, canGoBack, onStart, onNavigate, onBack, onQuit, onNewGame, onRetry,
|
|
|
|
|
|
}: SoloScreenProps) {
|
|
|
|
|
|
const breadcrumbEndRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
breadcrumbEndRef.current?.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "end" });
|
|
|
|
|
|
}, [history]);
|
|
|
|
|
|
|
2026-04-10 19:04:52 +02:00
|
|
|
|
const btnPrimary = "w-full min-h-11 rounded-xl text-sm font-semibold bg-[#7c3aed] text-white hover:bg-[#6d28d9] disabled:opacity-50 cursor-pointer transition-colors";
|
|
|
|
|
|
const btnGhost = "w-full min-h-11 rounded-xl text-sm font-semibold bg-[#242424] border border-[#2e2e2e] text-[#f0f0f0] hover:bg-[#1a1a1a] cursor-pointer transition-colors";
|
|
|
|
|
|
|
2026-04-10 18:58:41 +02:00
|
|
|
|
if (phase === "setup") return (
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<div className="min-h-dvh w-full bg-[#0f0f0f] text-[#f0f0f0] animate-fade-in flex flex-col items-center justify-center px-4 py-8 gap-5 max-w-sm mx-auto text-center">
|
|
|
|
|
|
<button className="self-start min-h-9 px-3 rounded-lg text-sm font-semibold bg-[#242424] border border-[#2e2e2e] text-[#f0f0f0] hover:bg-[#1a1a1a] cursor-pointer" onClick={onQuit}>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
Retour
|
|
|
|
|
|
</button>
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<h2 className="text-2xl sm:text-3xl font-black">Mode Solo</h2>
|
|
|
|
|
|
<p className="text-[#888] text-sm sm:text-base leading-relaxed">
|
2026-04-10 18:58:41 +02:00
|
|
|
|
Deux articles aléatoires seront choisis. Atteins l'article cible en cliquant uniquement sur les liens !
|
|
|
|
|
|
</p>
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<button className={btnPrimary} onClick={onStart} disabled={loading}>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
{loading ? "Préparation..." : "Lancer une partie"}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
2026-04-10 15:43:07 +02:00
|
|
|
|
|
2026-04-10 18:58:41 +02:00
|
|
|
|
if (phase === "won") return (
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<div className="min-h-dvh w-full bg-[#0f0f0f] text-[#f0f0f0] animate-fade-in flex items-center justify-center px-4 py-8">
|
|
|
|
|
|
<div className="w-full max-w-sm sm:max-w-md text-center flex flex-col gap-4 sm:gap-5">
|
|
|
|
|
|
<div className="text-5xl sm:text-6xl leading-none">🎉</div>
|
|
|
|
|
|
<h2 className="text-2xl sm:text-3xl font-black">Article atteint !</h2>
|
|
|
|
|
|
<div className="flex gap-6 sm:gap-8 justify-center">
|
2026-04-10 18:58:41 +02:00
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<span className="text-3xl sm:text-4xl font-black text-[#7c3aed]">{clicks}</span>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
<span className="text-xs text-[#888]">clics</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<span className="text-3xl sm:text-4xl font-black text-[#7c3aed]">{elapsedDisplay}</span>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
<span className="text-xs text-[#888]">temps</span>
|
2026-04-10 15:43:07 +02:00
|
|
|
|
</div>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
</div>
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<div className="bg-[#1a1a1a] rounded-xl px-3 sm:px-4 py-3 flex flex-wrap gap-1 text-xs sm:text-sm text-[#888] text-left">
|
2026-04-10 18:58:41 +02:00
|
|
|
|
{history.map((t, i) => (
|
|
|
|
|
|
<span key={i} className="flex items-center gap-1">
|
|
|
|
|
|
{i > 0 && <span className="text-[#555]">›</span>}
|
|
|
|
|
|
<span className={i === history.length - 1 ? "text-[#16a34a] font-semibold" : ""}>{t}</span>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
2026-04-10 22:57:31 +02:00
|
|
|
|
<ShareBar text={`🎉 J'ai atteint "${puzzle?.target}" en ${clicks} clics et ${elapsedDisplay} sur WikiRush !`} />
|
2026-04-10 18:58:41 +02:00
|
|
|
|
<div className="flex flex-col gap-2.5">
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<button className={btnPrimary} onClick={onNewGame}>Nouvelle partie</button>
|
|
|
|
|
|
<button className={btnGhost} onClick={onQuit}>Accueil</button>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
2026-04-10 15:43:07 +02:00
|
|
|
|
|
2026-04-10 19:04:52 +02:00
|
|
|
|
// Playing
|
2026-04-10 18:58:41 +02:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="min-h-dvh w-full bg-[#0f0f0f] flex flex-col">
|
|
|
|
|
|
<div className="flex-1 overflow-y-auto bg-white">
|
|
|
|
|
|
<div className="article-container">
|
|
|
|
|
|
{title && <h1 className="article-title">{title}</h1>}
|
|
|
|
|
|
{loading && (
|
|
|
|
|
|
<div className="flex items-center gap-3 py-10 px-4 text-[#888]">
|
|
|
|
|
|
<div className="spinner" /> Chargement...
|
2026-04-10 15:43:07 +02:00
|
|
|
|
</div>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
)}
|
|
|
|
|
|
{loadError && (
|
|
|
|
|
|
<div className="flex flex-col items-center gap-4 py-10 px-4 text-center">
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<p className="text-[#888] text-sm">{loadError}</p>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
<button className="min-h-11 px-5 rounded-xl text-sm font-semibold bg-[#2563eb] text-white hover:bg-[#1d4ed8] cursor-pointer" onClick={onRetry}>
|
|
|
|
|
|
Réessayer
|
2026-04-10 15:43:07 +02:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
)}
|
|
|
|
|
|
{!loading && !loadError && html && (
|
|
|
|
|
|
<ArticleView html={html} onNavigate={onNavigate} disabled={loading} />
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-04-10 15:43:07 +02:00
|
|
|
|
|
2026-04-10 18:58:41 +02:00
|
|
|
|
{/* Bottom bar */}
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<div className="fixed bottom-0 left-0 right-0 z-50 bg-[#0f0f0f]/97 backdrop-blur-sm border-t border-[#2e2e2e] flex items-center justify-between px-3 sm:px-4 py-2 gap-2 sm:gap-3">
|
|
|
|
|
|
<div className="flex-1 min-w-0 flex flex-col gap-0.5">
|
|
|
|
|
|
<span className="text-[8px] sm:text-[9px] font-bold tracking-widest text-[#888] uppercase">Trouver</span>
|
|
|
|
|
|
<span className="text-sm sm:text-base font-black text-[#7c3aed] truncate">{puzzle?.target}</span>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
<Breadcrumbs history={history} endRef={breadcrumbEndRef} />
|
|
|
|
|
|
</div>
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<div className="flex items-center gap-2 sm:gap-3 shrink-0">
|
|
|
|
|
|
<div className="flex flex-col items-center gap-0.5 min-w-10">
|
|
|
|
|
|
<span className="text-[8px] sm:text-[9px] font-bold tracking-wider text-[#888] uppercase">Temps</span>
|
|
|
|
|
|
<span className="text-xs sm:text-sm font-black tabular-nums">{elapsedDisplay}</span>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
</div>
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<div className="flex flex-col items-center gap-0.5 min-w-10">
|
|
|
|
|
|
<span className="text-[8px] sm:text-[9px] font-bold tracking-wider text-[#888] uppercase">Clics</span>
|
|
|
|
|
|
<span className="text-xs sm:text-sm font-black tabular-nums">{clicks}</span>
|
2026-04-10 15:43:07 +02:00
|
|
|
|
</div>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
{canGoBack && (
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<button className="min-h-8 sm:min-h-9 px-2 sm:px-3 rounded-lg text-xs font-semibold bg-[#242424] border border-[#2e2e2e] text-[#f0f0f0] hover:bg-[#1a1a1a] disabled:opacity-50 cursor-pointer" onClick={onBack} disabled={loading}>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
← +1
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)}
|
2026-04-10 19:04:52 +02:00
|
|
|
|
<button className="min-h-8 sm:min-h-9 px-2 sm:px-3 rounded-lg text-xs font-semibold bg-[#242424] border border-[#2e2e2e] text-[#f0f0f0] hover:bg-[#1a1a1a] cursor-pointer" onClick={onQuit}>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
Quitter
|
|
|
|
|
|
</button>
|
2026-04-10 15:43:07 +02:00
|
|
|
|
</div>
|
2026-04-10 18:58:41 +02:00
|
|
|
|
</div>
|
2026-04-10 15:43:07 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|