minor refactoring

main
Inga 🏳‍🌈 2 days ago
parent ab820c01bb
commit b4f7b51d7b
  1. 4
      src/backend/components/boardgame.tsx
  2. 6
      src/frontend/components/board-game.ts
  3. 5
      src/shared/display.ts

@ -22,10 +22,10 @@ const getCellHtml = ({
row: number; row: number;
column: number; column: number;
}) => { }) => {
const { isDisabled, nextGameState, text } = getCellDisplayData({ gameState, currentOutcome, row, column }); const { isDisabled, nextGameState, text, className } = getCellDisplayData({ gameState, currentOutcome, row, column });
return ( return (
<button {...getSubmitAttributes(key, nextGameState)} disabled={isDisabled} className={`square-${text}`}> <button {...getSubmitAttributes(key, nextGameState)} disabled={isDisabled} className={className}>
{text} {text}
</button> </button>
); );

@ -88,7 +88,7 @@ export class BoardGameComponent extends HTMLElement {
cell.append(button); cell.append(button);
} }
const { isDisabled, nextGameState, text } = getCellDisplayData({ const { isDisabled, nextGameState, text, className } = getCellDisplayData({
gameState, gameState,
currentOutcome, currentOutcome,
row: rowNumber, row: rowNumber,
@ -102,8 +102,8 @@ export class BoardGameComponent extends HTMLElement {
if (button.innerText !== text) { if (button.innerText !== text) {
button.innerText = text; button.innerText = text;
} }
if (button.className !== `square-${text}`) { if (button.className !== className) {
button.className = `square-${text}`; button.className = className;
} }
} }
} }

@ -28,6 +28,7 @@ export const getCellDisplayData = ({
nextGameState: gameState, nextGameState: gameState,
isDisabled: true, isDisabled: true,
text: " ", text: " ",
className: `square-empty`,
}; };
} }
@ -37,10 +38,12 @@ export const getCellDisplayData = ({
? gameState.withMove(row, column) ? gameState.withMove(row, column)
: gameState; : gameState;
const text = formatSquareState(squareState);
return { return {
nextGameState: nextGameState, nextGameState: nextGameState,
isDisabled: nextGameState === gameState, isDisabled: nextGameState === gameState,
text: formatSquareState(squareState), text,
className: `square-${text}`,
}; };
}; };

Loading…
Cancel
Save