sokko-g/website/src/features/cards/DailyResult.jsx
Shinuwa 880f007cce
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 23m0s
Validate and deploy Sokko G / deploy (push) Successful in 15s
Rework the daily card page around what the player knows and hints opened in any order
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:01:43 +01:00

53 lines
3.2 KiB
JavaScript

// Rôle : fin d'une partie de la Carte du jour : résultat, description, réponse détaillée, gains et résultat à partager.
import { useState } from "react";
import { SubjectChips } from "./DailyFeedback.jsx";
import { dailyKnowledge } from "./dailyKnowledge.js";
import { dailyShareText, fillTemplate, formatCountdown, formatStreak } from "./dailyShare.js";
import { DailyTrack } from "./DailyTrack.jsx";
import { formatStardust } from "./stardustFormat.js";
function wonTitle(count, content) {
return count === 1 ? content.wonFirstTitle : fillTemplate(content.wonTitle, { count });
}
export function DailyResult({ catalog, card, daily, content, now }) {
const [copied, setCopied] = useState(false);
const won = daily.status === "won";
const collection = catalog.collections.find((item) => item.id === card?.collectionId)?.name;
const { subject, theme } = daily.answerClues;
// Après une défaite, ce que les essais et l'indice ont trouvé reste en vert, le reste est en gris.
const known = dailyKnowledge(daily.guesses, daily.hints.find((hint) => hint.id === "theme")?.value ?? null);
async function share() {
const text = dailyShareText(daily, { title: content.shareTitle, url: `${window.location.origin}/#/cards/daily` });
try {
await navigator.clipboard.writeText(text);
setCopied(true);
} catch {
setCopied(false);
}
}
return <section className="nds-panel nebula-daily-result" aria-labelledby="nebula-daily-result-title" data-status={daily.status}>
<div className="nebula-daily-ask-heading">
<h3 id="nebula-daily-result-title">{won ? wonTitle(daily.guesses.length, content) : content.lostTitle}</h3>
{daily.hints.length > 0 && <span>{fillTemplate(daily.hints.length > 1 ? content.hintsUsedMany : content.hintsUsedOne, { count: daily.hints.length })}</span>}
</div>
<DailyTrack daily={daily} content={content} />
{card?.description && <p className="nebula-daily-description">{card.description}</p>}
<section className="nebula-daily-know" aria-labelledby="nebula-daily-answer-title">
<h4 id="nebula-daily-answer-title">{content.answerTitle}</h4>
<dl>
{subject.length > 0 && <><dt>{content.columnSubject}</dt><dd><SubjectChips labels={subject.map((step) => step.label)} isFound={(index) => won || index < known.path.length} /></dd></>}
{theme && <><dt>{content.columnTheme}</dt><dd><span className="nebula-daily-answer-theme"><SubjectChips labels={[theme.label]} isFound={() => won || Boolean(known.theme)} />{card && <span>« {card.name.slice(...theme.span)} »</span>}</span></dd></>}
{collection && <><dt>{content.hints.collection.title}</dt><dd>{collection}</dd></>}
</dl>
</section>
{won && <ul className="nebula-daily-rewards">
{daily.earned > 0 && <li>{fillTemplate(content.earned, { reward: formatStardust(daily.earned) })}</li>}
{daily.streak > 0 && <li>{fillTemplate(content.streak, { streak: formatStreak(daily.streak) })}</li>}
</ul>}
<div className="nebula-daily-result-actions">
<button className="nds-button" data-variant="primary" type="button" onClick={share}>{copied ? content.shared : content.share}</button>
<span>{fillTemplate(content.next, { time: formatCountdown(daily.nextAt - now) })}</span>
</div>
</section>;
}