feat : set board orientation on game load

This commit is contained in:
GuillaumeSD
2025-05-08 23:33:24 +02:00
parent 5cfac7700c
commit 9245125e13
4 changed files with 30 additions and 6 deletions

View File

@@ -28,10 +28,9 @@ export default function LoadGame() {
(pgn: string) => {
resetBoard({ fen: getStartingFen({ pgn }) });
setEval(undefined);
setBoardOrientation(true);
setGamePgn(pgn);
},
[resetBoard, setGamePgn, setEval, setBoardOrientation]
[resetBoard, setGamePgn, setEval]
);
useEffect(() => {
@@ -44,10 +43,11 @@ export default function LoadGame() {
resetAndSetGamePgn(gameFromUrl.pgn);
setEval(gameFromUrl.eval);
setBoardOrientation(true);
};
loadGame();
}, [gameFromUrl, game, resetAndSetGamePgn, setEval]);
}, [gameFromUrl, game, resetAndSetGamePgn, setEval, setBoardOrientation]);
const isGameLoaded =
gameFromUrl !== undefined ||

View File

@@ -10,7 +10,9 @@ import {
ListItemText,
TextField,
} from "@mui/material";
import { useSetAtom } from "jotai";
import { useEffect, useState } from "react";
import { boardOrientationAtom } from "../analysis/states";
interface Props {
onSelect: (pgn: string) => void;
@@ -22,6 +24,7 @@ export default function ChessComInput({ onSelect }: Props) {
"chesscom-username",
""
);
const setBoardOrientation = useSetAtom(boardOrientationAtom);
const [games, setGames] = useState<ChessComGame[]>([]);
useEffect(() => {
@@ -67,7 +70,13 @@ export default function ChessComInput({ onSelect }: Props) {
>
{games.map((game) => (
<ListItemButton
onClick={() => onSelect(game.pgn)}
onClick={() => {
setBoardOrientation(
chessComUsername.toLowerCase() !==
game.black.username.toLowerCase()
);
onSelect(game.pgn);
}}
style={{ width: 350, maxWidth: 350 }}
key={game.uuid}
>

View File

@@ -11,6 +11,8 @@ import {
TextField,
} from "@mui/material";
import { useEffect, useState } from "react";
import { useSetAtom } from "jotai";
import { boardOrientationAtom } from "../analysis/states";
interface Props {
onSelect: (pgn: string) => void;
@@ -22,6 +24,7 @@ export default function LichessInput({ onSelect }: Props) {
"lichess-username",
""
);
const setBoardOrientation = useSetAtom(boardOrientationAtom);
const [games, setGames] = useState<LichessGame[]>([]);
useEffect(() => {
@@ -67,7 +70,13 @@ export default function LichessInput({ onSelect }: Props) {
>
{games.map((game) => (
<ListItemButton
onClick={() => onSelect(game.pgn)}
onClick={() => {
setBoardOrientation(
lichessUsername.toLowerCase() !==
game.players.black.user?.name.toLowerCase()
);
onSelect(game.pgn);
}}
style={{ width: 350, maxWidth: 350 }}
key={game.id}
>

View File

@@ -22,6 +22,8 @@ import GamePgnInput from "./gamePgnInput";
import ChessComInput from "./chessComInput";
import { useLocalStorage } from "@/hooks/useLocalStorage";
import LichessInput from "./lichessInput";
import { useSetAtom } from "jotai";
import { boardOrientationAtom } from "../analysis/states";
interface Props {
open: boolean;
@@ -36,6 +38,7 @@ export default function NewGameDialog({ open, onClose, setGame }: Props) {
GameOrigin.Pgn
);
const [parsingError, setParsingError] = useState("");
const setBoardOrientation = useSetAtom(boardOrientationAtom);
const { addGame } = useGameDatabase();
const handleAddGame = (pgn: string) => {
@@ -140,7 +143,10 @@ export default function NewGameDialog({ open, onClose, setGame }: Props) {
<Button
variant="contained"
sx={{ marginLeft: 2 }}
onClick={() => handleAddGame(pgn)}
onClick={() => {
setBoardOrientation(true);
handleAddGame(pgn);
}}
>
Add
</Button>