Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : UQO Éval — Le Grand Défi Immobilier8 * File : apps/web/src/pages/Resume.tsx9 * Module : pages10 * Repository : https://git.spboucher.ai/uqo-eval-jeux11 * Project Website : https://jeux.uqo-eval.app12 * Created : 2026-11-2513 * Last Modified : 2026-11-2514 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { useEffect, useState } from "react";44import { Link, useLocation } from "wouter";45import { IconArrow } from "../components/Icons";46import { Logo } from "../components/Logo";47import { ApiError, api } from "../lib/api";48import { rememberGame, useGames } from "../lib/store";49import type { SessionView } from "../lib/types";5051export function Resume() {52 const [, navigate] = useLocation();53 const games = useGames();54 const [code, setCode] = useState("");55 const [error, setError] = useState<string | null>(null);56 const [busy, setBusy] = useState(false);57 useEffect(() => {58 document.title = "Reprendre ma partie — Le Grand Défi Immobilier";59 }, []);6061 const submit = async (): Promise<void> => {62 setBusy(true);63 setError(null);64 try {65 const res = await api<{ session: SessionView }>("/api/v1/sessions/resume", { method: "POST", body: { resumeCode: code } });66 const s = res.session;67 rememberGame({ id: s.id, mode: s.mode, competitionId: s.competitionId, name: s.competitionName, displayName: s.displayName, resumeCode: code.toUpperCase(), startedAt: Date.now() });68 navigate(s.status === "completed" ? `/resultats/${s.id}` : `/jouer/${s.id}`);69 } catch (e) {70 setError(e instanceof ApiError ? e.message : "Reprise impossible.");71 setBusy(false);72 }73 };7475 return (76 <div className="theme-night page-night">77 <header className="topbar"><Link href="/"><Logo /></Link></header>78 <main id="contenu" className="wrap-narrow stack" style={{ "--gap": "var(--s-6)", paddingBlock: "var(--s-7)" } as React.CSSProperties}>79 <div className="stack">80 <p className="kicker">Sauvegarde automatique</p>81 <h1 className="display" style={{ fontSize: "var(--step-4)" }}>Reprendre ma <em>partie</em></h1>82 <p className="lede">Votre progression est enregistrée après chaque réponse. Sur cet appareil, la reprise est immédiate ; ailleurs, entrez votre code de reprise.</p>83 </div>84 {games.length > 0 && (85 <section className="stack" aria-labelledby="parties-titre">86 <h2 id="parties-titre" className="eyebrow">Sur cet appareil</h2>87 <ul role="list" className="resume-list">88 {games.map((g) => (89 <li key={g.id}>90 <Link href={`/jouer/${g.id}`}>91 <span><strong>{g.name}</strong><span className="muted small"> · {g.displayName}</span></span>92 <IconArrow />93 </Link>94 </li>95 ))}96 </ul>97 </section>98 )}99 <form className="stack" onSubmit={(e) => { e.preventDefault(); void submit(); }}>100 <div className="field">101 <label htmlFor="code">Code de reprise (12 caractères)</label>102 <input id="code" className="input" style={{ fontSize: "var(--step-2)", letterSpacing: "0.1em", textTransform: "uppercase" }} value={code} onChange={(e) => setCode(e.target.value)} placeholder="XXXX-XXXX-XXXX" autoCapitalize="characters" autoComplete="off" spellCheck={false} maxLength={20} />103 </div>104 {error && <p className="error-text" role="alert">{error}</p>}105 <div className="row">106 <button type="submit" className="btn btn-primary btn-lg" disabled={busy || code.replace(/[^a-z0-9]/gi, "").length < 12}>Reprendre <IconArrow /></button>107 <Link href="/" className="btn btn-quiet">Retour à l'accueil</Link>108 </div>109 </form>110 </main>111 </div>112 );113}114