pass current fen and ply to state

This commit is contained in:
2026-06-02 14:44:18 +02:00
parent b8bd48885e
commit 98fbc4d253
3 changed files with 23 additions and 4 deletions
+14 -3
View File
@@ -1,15 +1,25 @@
import { type ChangeEvent, useReducer, useRef } from "react";
import { type ChangeEvent, useReducer, useRef, useState } from "react";
import { gameReducer, initialGameState } from "#/reducers/gameReducer.ts";
import { buildPgnString, getHeaders } from "#/utils/pgnUtils.ts";
import { downloadString } from "#/utils/stringUtils.ts";
interface IPosition {
ply: number;
fen: string;
}
export const useChessGame = () => {
const [gameState, gameDispatch] = useReducer(gameReducer, initialGameState);
const [currentPosition, setCurrentPosition] = useState<IPosition>({
ply: 0,
fen: "",
});
const fileInputRef = useRef<HTMLInputElement | null>(null);
const handlePlyChange = ({ ply, fen }: { ply: number; fen: string }) => {
console.log("Ply change", ply, fen);
return;
setCurrentPosition({ ply, fen });
};
const handleSavePgn = () => {
@@ -91,5 +101,6 @@ export const useChessGame = () => {
handleToggleClock,
handlePlyChange,
handleToggleDiagram,
currentPosition,
};
};