sokko-g/website/src/features/cards/DailyGuesses.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

54 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Rôle : grille des essais de la Carte du jour : la carte proposée, son sujet et son thème comparés à ceux de la réponse.
import { dailyGuessResult, DAILY_MARKS, fillTemplate } from "./dailyShare.js";
// Chemin du sujet : les étapes trouvées, puis la première qui diffère. Le chemin de la réponse n'est jamais montré.
function SubjectPath({ subject, content }) {
const steps = [...subject.common.map((step) => ({ label: step.label, same: true })), ...(subject.different ? [{ label: subject.different.label, same: false }] : [])];
return <span className="nebula-daily-path">{steps.map(({ label, same }, index) => <span key={label} className="nebula-daily-path-step">
{index > 0 && <span aria-hidden="true">›</span>}
<Compared label={label} same={same} text={same ? content.sameStep : content.differentStep} className="nebula-daily-step" />
</span>)}</span>;
}
// Vert : comme la réponse. Barré : différent. Le sens est aussi dit aux lecteurs d'écran.
function Compared({ label, same, text, className }) {
const Tag = same ? "b" : "s";
return <span className={className} data-same={same || undefined}><span className="sr-only">{fillTemplate(text, { label })}</span><Tag aria-hidden="true">{label}</Tag></span>;
}
// Nom de la carte, le mot qui donne son thème souligné.
function CardName({ name, theme }) {
if (!theme) return <strong>{name}</strong>;
const [start, end] = theme.span;
return <strong>{name.slice(0, start)}<u data-same={theme.same || undefined}>{name.slice(start, end)}</u>{name.slice(end)}</strong>;
}
function DailyFamilies({ content }) {
return <section className="nebula-daily-families" aria-label={content.guessesTitle}>
<p>{content.guessesEmpty}</p>
<ul>{content.families.map(({ name, text }) => <li key={name}><b>{name}</b><span>{text}</span></li>)}</ul>
</section>;
}
export function DailyGuesses({ catalog, daily, content }) {
if (!daily.guesses.length) return <DailyFamilies content={content} />;
const playing = daily.status === "playing";
const results = daily.guesses.map(dailyGuessResult);
return <section className="nebula-daily-guesses" aria-labelledby="nebula-daily-guesses-title">
<div className="nebula-daily-heading">
<h3 id="nebula-daily-guesses-title">{content.guessesTitle}</h3>
<p aria-hidden="true"><span><b>{content.keySame}</b>{content.keySameText}</span> <span><s>{content.keyDifferent}</s>{content.keyDifferentText}</span></p>
</div>
<div className="nebula-daily-columns" aria-hidden="true"><span /><span>{content.columnGuess}</span><span>{content.columnSubject}</span><span>{content.columnTheme}</span></div>
<ol>{daily.guesses.map((guess, index) => {
const result = results[index];
return <li key={guess.cardId} className="nebula-daily-guess" data-result={result} data-last={(playing && index === daily.guesses.length - 1) || undefined}>
<span className="nebula-daily-mark" data-result={result}><span aria-hidden="true">{DAILY_MARKS[result]}</span><span className="sr-only">{fillTemplate(content.attemptResult, { count: index + 1, result: content.results[result] })}</span></span>
<CardName name={catalog.cards.find((item) => item.id === guess.cardId)?.name || guess.cardId} theme={guess.theme} />
<SubjectPath subject={guess.subject} content={content} />
<span className="nebula-daily-theme-cell" data-label={content.columnTheme}>{guess.theme ? <Compared label={guess.theme.label} same={guess.theme.same} text={guess.theme.same ? content.sameTheme : content.differentTheme} className="nebula-daily-theme" /> : content.noTheme}</span>
</li>;
})}</ol>
<p className="nebula-daily-legend"><span>{content.legendTheme}</span>{results.includes("close") && <span><b aria-hidden="true">{DAILY_MARKS.close}</b> {content.legendClose}</span>}</p>
</section>;
}