diff --git a/src/hooks/useScreenSize.ts b/src/hooks/useScreenSize.ts index 1e91623..aa2f1ba 100644 --- a/src/hooks/useScreenSize.ts +++ b/src/hooks/useScreenSize.ts @@ -35,17 +35,5 @@ export const useScreenSize = () => { }; }, []); - const getBoardSize = () => { - const width = screenSize.width; - const height = screenSize.height; - - // 1200 is the lg layout breakpoint - if (window?.innerWidth < 1200) { - return Math.min(width, height - 150); - } - - return Math.min(width - 600, height * 0.95); - }; - - return { ...screenSize, boardSize: getBoardSize() }; + return screenSize; }; diff --git a/src/pages/play.tsx b/src/pages/play.tsx index d371b5e..181da05 100644 --- a/src/pages/play.tsx +++ b/src/pages/play.tsx @@ -16,14 +16,14 @@ export default function Play() { diff --git a/src/sections/analysis/board/index.tsx b/src/sections/analysis/board/index.tsx index c26c5c6..c8780fa 100644 --- a/src/sections/analysis/board/index.tsx +++ b/src/sections/analysis/board/index.tsx @@ -20,7 +20,7 @@ import SquareRenderer, { moveClassificationColors } from "./squareRenderer"; export default function Board() { const boardRef = useRef(null); - const { boardSize } = useScreenSize(); + const screenSize = useScreenSize(); const board = useAtomValue(boardAtom); const boardOrientation = useAtomValue(boardOrientationAtom); const showBestMoveArrow = useAtomValue(showBestMoveArrowAtom); @@ -91,6 +91,18 @@ export default function Board() { return []; }, [position, showBestMoveArrow]); + const boardSize = useMemo(() => { + const width = screenSize.width; + const height = screenSize.height; + + // 1200 is the lg layout breakpoint + if (window?.innerWidth < 1200) { + return Math.min(width, height - 150); + } + + return Math.min(width - 600, height * 0.95); + }, [screenSize]); + return ( (null); - const { boardSize } = useScreenSize(); + const screenSize = useScreenSize(); const engine = useEngine(EngineName.Stockfish16); const game = useAtomValue(gameAtom); const playerColor = useAtomValue(playerColorAtom); @@ -106,6 +106,18 @@ export default function Board() { setPlayableSquares([]); }; + const boardSize = useMemo(() => { + const width = screenSize.width; + const height = screenSize.height; + + // 900 is the md layout breakpoint + if (window?.innerWidth < 900) { + return Math.min(width, height - 150); + } + + return Math.min(width - 300, height * 0.85); + }, [screenSize]); + return (