From c02782d2951c017e63674e4bef0ff7f140ebc407 Mon Sep 17 00:00:00 2001 From: GuillaumeSD Date: Sun, 25 May 2025 18:50:37 +0200 Subject: [PATCH] fix : load game throwing outside trycatch --- src/components/board/capturedPieces.tsx | 5 +++-- src/sections/loadGame/loadGameButton.tsx | 2 +- src/sections/loadGame/loadGameDialog.tsx | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/components/board/capturedPieces.tsx b/src/components/board/capturedPieces.tsx index 39e1f18..ddd4d94 100644 --- a/src/components/board/capturedPieces.tsx +++ b/src/components/board/capturedPieces.tsx @@ -60,8 +60,9 @@ const getCapturedPiecesComponents = ( key={pieceSymbol} spacing={`-${1.2 * PIECE_SCALE}rem`} > - {new Array(pieceCount).fill( + {new Array(pieceCount).fill(0).map((_, index) => ( - )} + ))} ); }; diff --git a/src/sections/loadGame/loadGameButton.tsx b/src/sections/loadGame/loadGameButton.tsx index 5db4c4c..b6bf37e 100644 --- a/src/sections/loadGame/loadGameButton.tsx +++ b/src/sections/loadGame/loadGameButton.tsx @@ -4,7 +4,7 @@ import NewGameDialog from "./loadGameDialog"; import { Chess } from "chess.js"; interface Props { - setGame?: (game: Chess) => void; + setGame?: (game: Chess) => Promise; label?: string; size?: "small" | "medium" | "large"; } diff --git a/src/sections/loadGame/loadGameDialog.tsx b/src/sections/loadGame/loadGameDialog.tsx index a1d3192..c62324b 100644 --- a/src/sections/loadGame/loadGameDialog.tsx +++ b/src/sections/loadGame/loadGameDialog.tsx @@ -29,7 +29,7 @@ import { boardOrientationAtom } from "../analysis/states"; interface Props { open: boolean; onClose: () => void; - setGame?: (game: Chess) => void; + setGame?: (game: Chess) => Promise; } export default function NewGameDialog({ open, onClose, setGame }: Props) { @@ -43,7 +43,7 @@ export default function NewGameDialog({ open, onClose, setGame }: Props) { const setBoardOrientation = useSetAtom(boardOrientationAtom); const { addGame } = useGameDatabase(); - const handleAddGame = (pgn: string, boardOrientation?: boolean) => { + const handleAddGame = async (pgn: string, boardOrientation?: boolean) => { if (!pgn) return; try { @@ -51,9 +51,9 @@ export default function NewGameDialog({ open, onClose, setGame }: Props) { setSentryContext("loadedGame", { pgn }); if (setGame) { - setGame(gameToAdd); + await setGame(gameToAdd); } else { - addGame(gameToAdd); + await addGame(gameToAdd); } setBoardOrientation(boardOrientation ?? true); @@ -92,10 +92,12 @@ export default function NewGameDialog({ open, onClose, setGame }: Props) { onClose={handleClose} maxWidth="md" fullWidth - PaperProps={{ - sx: { - position: "fixed", - top: 0, + slotProps={{ + paper: { + sx: { + position: "fixed", + top: 0, + }, }, }} >