From 5ed83a20d807e111d57c19407ea59663ea319e08 Mon Sep 17 00:00:00 2001 From: Owen Date: Tue, 2 Jun 2026 22:33:27 +0200 Subject: [PATCH] populate header fields --- src/components/CustomHeaders.tsx | 15 +++++++++----- src/components/FormField.tsx | 10 ++++++++- src/components/HeaderFields.tsx | 35 +++++++++++++++++++------------- src/hooks/useChessGame.ts | 15 +++++++++++++- src/interfaces.ts | 3 +++ src/pages/Chessboard.tsx | 6 +++--- 6 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/components/CustomHeaders.tsx b/src/components/CustomHeaders.tsx index 822c903..c206297 100644 --- a/src/components/CustomHeaders.tsx +++ b/src/components/CustomHeaders.tsx @@ -1,6 +1,11 @@ import FormField from "#/components/FormField.tsx"; +import type { IHeader } from "#/interfaces.ts"; -const CustomHeaders = () => { +interface IProps { + headers: IHeader; +} + +const CustomHeaders = ({ headers }: IProps) => { return (
@@ -13,10 +18,10 @@ const CustomHeaders = () => {
- - - - + + + +
diff --git a/src/components/FormField.tsx b/src/components/FormField.tsx index 8ec4c31..0f5fdc1 100644 --- a/src/components/FormField.tsx +++ b/src/components/FormField.tsx @@ -1,9 +1,15 @@ +import { useChessGame } from "#/hooks/useChessGame.ts"; +import type { IHeader } from "#/interfaces.ts"; + export interface IFormField { fieldName: string; type: string; + headers: IHeader; } -const FormField = ({ fieldName, type }: IFormField) => { +const FormField = ({ fieldName, type, headers }: IFormField) => { + const { updateHeaders } = useChessGame(); + return (
); diff --git a/src/components/HeaderFields.tsx b/src/components/HeaderFields.tsx index 843f012..069c7af 100644 --- a/src/components/HeaderFields.tsx +++ b/src/components/HeaderFields.tsx @@ -1,6 +1,13 @@ import FormField from "#/components/FormField.tsx"; +import type { IHeader } from "#/interfaces.ts"; + +interface IProps { + headers: IHeader; +} + +const HeaderFields = ({ headers }: IProps) => { + console.log(headers); -const HeaderFields = () => { return (
@@ -10,19 +17,19 @@ const HeaderFields = () => {
- - - - - - - - - - - - - + + + + + + + + + + + + +
diff --git a/src/hooks/useChessGame.ts b/src/hooks/useChessGame.ts index 103240f..75d4232 100644 --- a/src/hooks/useChessGame.ts +++ b/src/hooks/useChessGame.ts @@ -6,7 +6,7 @@ import { useState, } from "react"; import { toast } from "react-toastify"; -import type { IPosition } from "#/interfaces.ts"; +import type { IHeader, IPosition } from "#/interfaces.ts"; import { gameReducer, initialGameState } from "#/reducers/gameReducer.ts"; import { downloadPDF } from "#/utils/pdfUtils.ts"; import { buildPgnString, getHeaders } from "#/utils/pgnUtils.ts"; @@ -153,6 +153,18 @@ export const useChessGame = () => { ); }; + const updateHeaders = ( + e: ChangeEvent, + fieldName: string, + ) => { + e.preventDefault(); + const updatedHeaders = { + ...gameState.headers, + [fieldName]: e.target.value, + } as IHeader; + gameDispatch({ type: "SET_HEADERS", payload: updatedHeaders }); + }; + return { gameState, fileInputRef, @@ -165,5 +177,6 @@ export const useChessGame = () => { handleToggleDiagram, currentPosition, generatingPdf, + updateHeaders, }; }; diff --git a/src/interfaces.ts b/src/interfaces.ts index 6e614ea..642eaca 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -17,6 +17,9 @@ export interface IHeader { plyCount: string; eventDate: string; source: string; + title: string; + subtitle: string; + author: string; [key: string]: string; } diff --git a/src/pages/Chessboard.tsx b/src/pages/Chessboard.tsx index ec77d95..c94c23f 100644 --- a/src/pages/Chessboard.tsx +++ b/src/pages/Chessboard.tsx @@ -23,7 +23,7 @@ const Chessboard = () => { return (
- or{" "} + console.log("Lichess Login")} /> or{" "} {
- - + +