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
21 lines
623 B
TypeScript
21 lines
623 B
TypeScript
import { CurrentPosition } from "@/types/eval";
|
|
import { Chess } from "chess.js";
|
|
import { PrimitiveAtom, useAtom, useAtomValue } from "jotai";
|
|
import { useEffect } from "react";
|
|
|
|
export const useGameData = (
|
|
gameAtom: PrimitiveAtom<Chess>,
|
|
gameDataAtom: PrimitiveAtom<CurrentPosition>
|
|
) => {
|
|
const game = useAtomValue(gameAtom);
|
|
const [gameData, setGameData] = useAtom(gameDataAtom);
|
|
|
|
useEffect(() => {
|
|
const history = game.history({ verbose: true });
|
|
const lastMove = history.at(-1);
|
|
setGameData({ lastMove });
|
|
}, [game]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
return gameData;
|
|
};
|