feat : open played game in analysis

This commit is contained in:
GuillaumeSD
2024-03-20 03:50:20 +01:00
parent aca8910bab
commit 32fc196e74
8 changed files with 118 additions and 33 deletions

View File

@@ -1,7 +1,14 @@
import { setGameHeaders } from "@/lib/chess";
import { Chess, Move } from "chess.js";
import { PrimitiveAtom, useAtom } from "jotai";
import { useCallback } from "react";
export interface resetGameParams {
fen?: string;
whiteName?: string;
blackName?: string;
}
export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
const [game, setGame] = useAtom(chessAtom);
@@ -15,8 +22,10 @@ export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
);
const reset = useCallback(
(fen?: string) => {
setGame(new Chess(fen));
(params?: resetGameParams) => {
const newGame = new Chess(params?.fen);
setGameHeaders(newGame, params);
setGame(newGame);
},
[setGame]
);