diff --git a/src/backend/components/boardgame.tsx b/src/backend/components/boardgame.tsx index 9a755cb..ca46281 100644 --- a/src/backend/components/boardgame.tsx +++ b/src/backend/components/boardgame.tsx @@ -6,6 +6,16 @@ import { SquareState, formatSquareState, } from "../../shared/datatypes.ts"; +import { ClassNames, getDisplayStates } from "../../shared/display.ts"; + +const getClassAndDisplayAttributes = ( + className: ClassNames, + gameState: BoardgameStateType, + currentOutcome: CurrentOutcome, +) => ({ + class: className, + style: getDisplayStates(gameState, currentOutcome)[className] ? {} : { display: "none" }, +}); const getCellHtml = ({ key, @@ -61,25 +71,15 @@ export const getBoardgameHtml = (key: string, gameState: BoardgameStateType, rul
- - Player X won - - - Player O won - - - Draw - + Player X won + Player O won + Draw
diff --git a/src/shared/display.ts b/src/shared/display.ts new file mode 100644 index 0000000..0a08d3e --- /dev/null +++ b/src/shared/display.ts @@ -0,0 +1,11 @@ +import { BoardgameStateType, CurrentOutcome } from "./datatypes.ts"; + +export const getDisplayStates = (gameState: BoardgameStateType, currentOutcome: CurrentOutcome) => ({ + "outcome-winx": currentOutcome === CurrentOutcome.WinX, + "outcome-wino": currentOutcome === CurrentOutcome.WinO, + "outcome-draw": currentOutcome === CurrentOutcome.Draw, + "start-new-game": !gameState.board, + "start-clear-game": gameState.board, +}); + +export type ClassNames = keyof ReturnType