diff --git a/src/components/PgnViewer.tsx b/src/components/PgnViewer.tsx index 5e44dcf..5728275 100644 --- a/src/components/PgnViewer.tsx +++ b/src/components/PgnViewer.tsx @@ -19,6 +19,12 @@ const PgnViewer = ({ gamePgn, handlePlyChange }: IProps) => { scrollToMove: false, }); + // set initial position - TODO change onto file load + // handlePlyChange({ + // ply: 0, + // fen: viewerRef.current?.curData().fen, + // }); + const boardButtons = document.querySelectorAll(".lpv__controls"); const movesList = document.querySelectorAll(".lpv__moves"); if (!boardButtons || !movesList) return; @@ -71,7 +77,7 @@ const PgnViewer = ({ gamePgn, handlePlyChange }: IProps) => { move.removeEventListener("touchstart", clickHandlerDelay); }); }; - }, [gamePgn, handlePlyChange]); + }, [gamePgn]); return
; }; diff --git a/src/hooks/useChessGame.ts b/src/hooks/useChessGame.ts index 29b0f28..cba585e 100644 --- a/src/hooks/useChessGame.ts +++ b/src/hooks/useChessGame.ts @@ -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