mirror of
https://github.com/TheRealOwenRees/chess-scribe-website.git
synced 2026-07-23 01:46:57 +00:00
pass current fen and ply to state
This commit is contained in:
@@ -19,6 +19,12 @@ const PgnViewer = ({ gamePgn, handlePlyChange }: IProps) => {
|
|||||||
scrollToMove: false,
|
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 boardButtons = document.querySelectorAll(".lpv__controls");
|
||||||
const movesList = document.querySelectorAll(".lpv__moves");
|
const movesList = document.querySelectorAll(".lpv__moves");
|
||||||
if (!boardButtons || !movesList) return;
|
if (!boardButtons || !movesList) return;
|
||||||
@@ -71,7 +77,7 @@ const PgnViewer = ({ gamePgn, handlePlyChange }: IProps) => {
|
|||||||
move.removeEventListener("touchstart", clickHandlerDelay);
|
move.removeEventListener("touchstart", clickHandlerDelay);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}, [gamePgn, handlePlyChange]);
|
}, [gamePgn]);
|
||||||
|
|
||||||
return <div ref={containerRef} className="lpv-board" />;
|
return <div ref={containerRef} className="lpv-board" />;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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 { gameReducer, initialGameState } from "#/reducers/gameReducer.ts";
|
||||||
import { buildPgnString, getHeaders } from "#/utils/pgnUtils.ts";
|
import { buildPgnString, getHeaders } from "#/utils/pgnUtils.ts";
|
||||||
import { downloadString } from "#/utils/stringUtils.ts";
|
import { downloadString } from "#/utils/stringUtils.ts";
|
||||||
|
|
||||||
|
interface IPosition {
|
||||||
|
ply: number;
|
||||||
|
fen: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const useChessGame = () => {
|
export const useChessGame = () => {
|
||||||
const [gameState, gameDispatch] = useReducer(gameReducer, initialGameState);
|
const [gameState, gameDispatch] = useReducer(gameReducer, initialGameState);
|
||||||
|
|
||||||
|
const [currentPosition, setCurrentPosition] = useState<IPosition>({
|
||||||
|
ply: 0,
|
||||||
|
fen: "",
|
||||||
|
});
|
||||||
|
|
||||||
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
const handlePlyChange = ({ ply, fen }: { ply: number; fen: string }) => {
|
const handlePlyChange = ({ ply, fen }: { ply: number; fen: string }) => {
|
||||||
console.log("Ply change", ply, fen);
|
setCurrentPosition({ ply, fen });
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSavePgn = () => {
|
const handleSavePgn = () => {
|
||||||
@@ -91,5 +101,6 @@ export const useChessGame = () => {
|
|||||||
handleToggleClock,
|
handleToggleClock,
|
||||||
handlePlyChange,
|
handlePlyChange,
|
||||||
handleToggleDiagram,
|
handleToggleDiagram,
|
||||||
|
currentPosition,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import Chessboard from "#/pages/Chessboard.tsx";
|
|||||||
const ChessboardContainer = () => {
|
const ChessboardContainer = () => {
|
||||||
const chessGameProps = useChessGame();
|
const chessGameProps = useChessGame();
|
||||||
|
|
||||||
|
console.log(chessGameProps.currentPosition);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chessboard
|
<Chessboard
|
||||||
gameState={chessGameProps.gameState}
|
gameState={chessGameProps.gameState}
|
||||||
|
|||||||
Reference in New Issue
Block a user