2026-10-16 00:27:06 +03:00
|
|
|
import * as React from "react";
|
|
|
|
|
import { FunctionComponent } from "react";
|
2026-10-16 10:21:46 +03:00
|
|
|
import { getPlayerDisplayName, LiveGameSummary } from "@mancala/core";
|
2026-10-16 00:27:06 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2026-10-16 10:21:46 +03:00
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
import MiniBoard, { getStores } from "./MiniBoard";
|
2026-10-16 00:27:06 +03:00
|
|
|
|
|
|
|
|
// Shown at the top of the home page while the user has a game in progress.
|
|
|
|
|
const ActiveGameBanner: FunctionComponent<{
|
|
|
|
|
game: LiveGameSummary,
|
|
|
|
|
userId: string,
|
|
|
|
|
onContinue: () => void,
|
2026-10-16 10:21:46 +03:00
|
|
|
}> = ({ game, userId, onContinue }) => {
|
2026-10-16 00:27:06 +03:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const opponent = game.player1.userId === userId ? game.player2 : game.player1;
|
2026-10-16 10:21:46 +03:00
|
|
|
const revert = game.player2.userId === userId;
|
|
|
|
|
const stores = getStores(game.board, revert);
|
|
|
|
|
const details = [
|
|
|
|
|
game.turnPlayerId === userId ? t("YourTurn") : t("OpponentTurn"),
|
|
|
|
|
t("MoveNumber", { number: game.moveCount }),
|
|
|
|
|
t("StoreScores", { mine: stores.bottom, theirs: stores.top }),
|
|
|
|
|
].join(" · ");
|
2026-10-16 00:27:06 +03:00
|
|
|
return (
|
2026-10-16 10:21:46 +03:00
|
|
|
<section className="hero" aria-label={t("GameInProgress")}>
|
2026-10-16 00:27:06 +03:00
|
|
|
<div>
|
2026-10-16 10:21:46 +03:00
|
|
|
<span className="pill live">{t("GameInProgress")}</span>
|
|
|
|
|
<h1>{t("GameWithOpponent", { name: getPlayerDisplayName(opponent, t) ?? t("Anonymous") })}</h1>
|
|
|
|
|
<p>{details}</p>
|
|
|
|
|
<div className="row">
|
|
|
|
|
<button className="btn pri" onClick={onContinue}>{t("Continue")}</button>
|
|
|
|
|
</div>
|
2026-10-16 00:27:06 +03:00
|
|
|
</div>
|
2026-10-16 10:21:46 +03:00
|
|
|
<Link className="hero-board" to={`/game/${game.id}`} aria-label={t("OpenGame")}>
|
|
|
|
|
<MiniBoard board={game.board} revert={revert} large />
|
|
|
|
|
</Link>
|
|
|
|
|
</section>
|
2026-10-16 00:27:06 +03:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ActiveGameBanner;
|