From c1d47601b443ff8f7c13856648f080a4585a82f8 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Thu, 2 Jul 2026 23:40:45 +0300 Subject: [PATCH] fix: display stone count immediately on board pits --- .../src/components/board/BoardView.tsx | 17 ++++++++- .../frontend/src/components/board/PitView.tsx | 38 +++++++++++++++++-- .../mobile/src/components/board/BoardView.tsx | 5 ++- apps/mobile/src/components/board/PitView.tsx | 34 ++++++++++++----- 4 files changed, 78 insertions(+), 16 deletions(-) diff --git a/apps/frontend/src/components/board/BoardView.tsx b/apps/frontend/src/components/board/BoardView.tsx index e6ec78c..f53ce18 100644 --- a/apps/frontend/src/components/board/BoardView.tsx +++ b/apps/frontend/src/components/board/BoardView.tsx @@ -14,12 +14,23 @@ const BoardView: FunctionComponent<{ boardViewModel: BoardViewModel; revert: boolean; onPitSelect: (index: number, pit: Pit) => void; -}> = ({ game, context, boardId, boardViewModel, revert, onPitSelect: onPitSelect }) => { +}> = ({ game, context, boardId, boardViewModel, revert, onPitSelect }) => { const mancalaGame = game?.mancalaGame; const theme = context.themeManager.theme; + // Compute pit width based on viewport (each column is 11vw) + const pitWidth = typeof window !== "undefined" ? window.innerWidth * 0.11 : 100; + const createPitView = (key: any, pit: Pit, pitViewModel: PitViewModel) => { - return onPitSelect(pit.index, pit)} />; + return ( + onPitSelect(pit.index, pit)} + fontSize={pitWidth / 5} + /> + ); }; const createPitViewList = (pits: Pit[]) => pits.map((pit, index) => createPitView(index, pit, boardViewModel.pits[pit.index])); @@ -36,12 +47,14 @@ const BoardView: FunctionComponent<{ pitViewModel={revert ? player2BankViewModel : player1BankViewModel} gridColumn="8 / 9" gridRow="1 / 3" + fontSize={pitWidth / 6} /> {revert ? player1Pits?.reverse() : player2Pits?.reverse()} {revert ? player2Pits : player1Pits} diff --git a/apps/frontend/src/components/board/PitView.tsx b/apps/frontend/src/components/board/PitView.tsx index b2a3398..bbc24be 100644 --- a/apps/frontend/src/components/board/PitView.tsx +++ b/apps/frontend/src/components/board/PitView.tsx @@ -1,20 +1,50 @@ import * as React from "react"; import { FunctionComponent } from "react"; import Util from "../../util/Util"; -import { PitViewModel } from "@mancala/core"; +import { PitViewModel, getColorByBrightness } from "@mancala/core"; +import { Context } from "../../context/context"; import StoneView from "./StoneView"; const PitView: FunctionComponent<{ pitViewModel: PitViewModel; + context: Context; onClick: () => void; -}> = ({ pitViewModel, onClick }) => { + fontSize: number; +}> = ({ pitViewModel, context, onClick, fontSize }) => { const stones = [...Util.range(pitViewModel.stoneCount)].map((i, index) => ( )); - + const textColor = getColorByBrightness( + pitViewModel.pitColor, + context.themeManager.theme.textColor, + context.themeManager.theme.textLightColor + ); return ( -
+
{stones} + {pitViewModel.stoneCount > 0 && ( + + {pitViewModel.stoneCount} + + )}