allow showing past game

This commit is contained in:
MasterGordon 2024-10-12 01:23:15 +02:00
parent ac9543267a
commit 538750b691
4 changed files with 19 additions and 5 deletions

View File

@ -241,7 +241,7 @@ const Tile = ({
const isFlagged = game.isFlagged[i][j]; const isFlagged = game.isFlagged[i][j];
const isQuestionMark = game.isQuestionMark[i][j]; const isQuestionMark = game.isQuestionMark[i][j];
const base = const base =
isRevealed || isMine ? ( isRevealed || (isMine && !isFlagged) ? (
<Sprite key="b" texture={theme.revealed} /> <Sprite key="b" texture={theme.revealed} />
) : ( ) : (
<Sprite key="b" texture={theme.tile} /> <Sprite key="b" texture={theme.tile} />

View File

@ -1,3 +1,4 @@
import { Link } from "wouter";
import { ServerGame } from "../../shared/game"; import { ServerGame } from "../../shared/game";
import { formatRelativeTime, formatTimeSpan } from "../../shared/time"; import { formatRelativeTime, formatTimeSpan } from "../../shared/time";
import { Button } from "./Button"; import { Button } from "./Button";
@ -27,7 +28,10 @@ const PastMatch = ({ game }: PastMatchProps) => {
<div>Duration: {formatTimeSpan(game.finished - game.started)}</div> <div>Duration: {formatTimeSpan(game.finished - game.started)}</div>
</div> </div>
<div className="flex justify-end"> <div className="flex justify-end">
<Button variant="outline">Show Board</Button> {/* @ts-expect-error as is cheaply typed */}
<Button as={Link} href={`/play/${game.uuid}`} variant="outline">
Show Board
</Button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -33,7 +33,9 @@ setup().then(() => {
<Shell> <Shell>
<Switch> <Switch>
<Route path="/" component={Home} /> <Route path="/" component={Home} />
<Route path="/play" component={Endless} /> <Route path="/play/:gameId?">
{(params) => <Endless gameId={params.gameId} />}
</Route>
<Route path="/history" component={MatchHistory} /> <Route path="/history" component={MatchHistory} />
<Route path="/settings" component={Settings} /> <Route path="/settings" component={Settings} />
</Switch> </Switch>

View File

@ -7,7 +7,11 @@ import { Button } from "../../components/Button";
import LeaderboardButton from "../../components/LeaderboardButton"; import LeaderboardButton from "../../components/LeaderboardButton";
import { Fragment, useEffect } from "react"; import { Fragment, useEffect } from "react";
const Endless = () => { interface EndlessProps {
gameId?: string;
}
const Endless: React.FC<EndlessProps> = (props) => {
const [gameId, setGameId] = useAtom(gameIdAtom); const [gameId, setGameId] = useAtom(gameIdAtom);
const { data: game } = useWSQuery("game.getGameState", gameId!, !!gameId); const { data: game } = useWSQuery("game.getGameState", gameId!, !!gameId);
const { data: settings } = useWSQuery("user.getSettings", null); const { data: settings } = useWSQuery("user.getSettings", null);
@ -17,11 +21,15 @@ const Endless = () => {
const placeFlag = useWSMutation("game.placeFlag"); const placeFlag = useWSMutation("game.placeFlag");
const placeQuestionMark = useWSMutation("game.placeQuestionMark"); const placeQuestionMark = useWSMutation("game.placeQuestionMark");
const clearTile = useWSMutation("game.clearTile"); const clearTile = useWSMutation("game.clearTile");
useEffect(() => { useEffect(() => {
if (props.gameId) {
setGameId(props.gameId);
}
return () => { return () => {
setGameId(undefined); setGameId(undefined);
}; };
}, [setGameId]); }, [props.gameId, setGameId]);
return game ? ( return game ? (
<> <>