fix : load game throwing outside trycatch

This commit is contained in:
GuillaumeSD
2025-05-25 18:50:37 +02:00
parent ea28844d93
commit c02782d295
3 changed files with 14 additions and 11 deletions

View File

@@ -60,8 +60,9 @@ const getCapturedPiecesComponents = (
key={pieceSymbol} key={pieceSymbol}
spacing={`-${1.2 * PIECE_SCALE}rem`} spacing={`-${1.2 * PIECE_SCALE}rem`}
> >
{new Array(pieceCount).fill( {new Array(pieceCount).fill(0).map((_, index) => (
<Box <Box
key={`${pieceSymbol}-${index}`}
width={`${2 * PIECE_SCALE}rem`} width={`${2 * PIECE_SCALE}rem`}
height={`${2 * PIECE_SCALE}rem`} height={`${2 * PIECE_SCALE}rem`}
sx={{ sx={{
@@ -69,7 +70,7 @@ const getCapturedPiecesComponents = (
backgroundRepeat: "no-repeat", backgroundRepeat: "no-repeat",
}} }}
/> />
)} ))}
</Stack> </Stack>
); );
}; };

View File

@@ -4,7 +4,7 @@ import NewGameDialog from "./loadGameDialog";
import { Chess } from "chess.js"; import { Chess } from "chess.js";
interface Props { interface Props {
setGame?: (game: Chess) => void; setGame?: (game: Chess) => Promise<void>;
label?: string; label?: string;
size?: "small" | "medium" | "large"; size?: "small" | "medium" | "large";
} }

View File

@@ -29,7 +29,7 @@ import { boardOrientationAtom } from "../analysis/states";
interface Props { interface Props {
open: boolean; open: boolean;
onClose: () => void; onClose: () => void;
setGame?: (game: Chess) => void; setGame?: (game: Chess) => Promise<void>;
} }
export default function NewGameDialog({ open, onClose, setGame }: Props) { 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 setBoardOrientation = useSetAtom(boardOrientationAtom);
const { addGame } = useGameDatabase(); const { addGame } = useGameDatabase();
const handleAddGame = (pgn: string, boardOrientation?: boolean) => { const handleAddGame = async (pgn: string, boardOrientation?: boolean) => {
if (!pgn) return; if (!pgn) return;
try { try {
@@ -51,9 +51,9 @@ export default function NewGameDialog({ open, onClose, setGame }: Props) {
setSentryContext("loadedGame", { pgn }); setSentryContext("loadedGame", { pgn });
if (setGame) { if (setGame) {
setGame(gameToAdd); await setGame(gameToAdd);
} else { } else {
addGame(gameToAdd); await addGame(gameToAdd);
} }
setBoardOrientation(boardOrientation ?? true); setBoardOrientation(boardOrientation ?? true);
@@ -92,11 +92,13 @@ export default function NewGameDialog({ open, onClose, setGame }: Props) {
onClose={handleClose} onClose={handleClose}
maxWidth="md" maxWidth="md"
fullWidth fullWidth
PaperProps={{ slotProps={{
paper: {
sx: { sx: {
position: "fixed", position: "fixed",
top: 0, top: 0,
}, },
},
}} }}
> >
<DialogTitle marginY={1} variant="h5"> <DialogTitle marginY={1} variant="h5">