Squashed commit of the following:

commit dbb5ce37add830b04e3cb977ca5caa9ae9429001
Author: GuillaumeSD <gsd.lfny@gmail.com>
Date:   Tue Mar 26 03:07:38 2024 +0100

    feat : add move click

commit a6d1d10d452a1e556b6e2ecb1fd12ada135b96d0
Author: GuillaumeSD <gsd.lfny@gmail.com>
Date:   Tue Mar 26 01:44:49 2024 +0100

    feat : board refacto done

commit 55f7d6dbac4cb135796cf66120de613e0bf34462
Author: GuillaumeSD <gsd.lfny@gmail.com>
Date:   Sun Mar 24 04:00:35 2024 +0100

    feat : add click to move
This commit is contained in:
GuillaumeSD
2024-03-26 03:08:34 +01:00
parent 8355dbc4e8
commit cd514d90cf
16 changed files with 557 additions and 560 deletions

View File

@@ -1,15 +1,11 @@
import { Chess, Move } from "chess.js";
import { CurrentPosition } from "@/types/eval";
import { Chess } from "chess.js";
import { PrimitiveAtom, useAtom, useAtomValue } from "jotai";
import { useEffect } from "react";
export interface GameData {
history: Move[];
lastMove: Move | undefined;
}
export const useGameData = (
gameAtom: PrimitiveAtom<Chess>,
gameDataAtom: PrimitiveAtom<GameData>
gameDataAtom: PrimitiveAtom<CurrentPosition>
) => {
const game = useAtomValue(gameAtom);
const [gameData, setGameData] = useAtom(gameDataAtom);
@@ -17,7 +13,7 @@ export const useGameData = (
useEffect(() => {
const history = game.history({ verbose: true });
const lastMove = history.at(-1);
setGameData({ history, lastMove });
setGameData({ lastMove });
}, [game]); // eslint-disable-line react-hooks/exhaustive-deps
return gameData;