diff --git a/src/components/SelectStudyChapter.tsx b/src/components/SelectStudyChapter.tsx index b3dca22..a4cc0a8 100644 --- a/src/components/SelectStudyChapter.tsx +++ b/src/components/SelectStudyChapter.tsx @@ -1,9 +1,10 @@ -import { useRef, useState } from "react"; +import { useRef, useState, type Dispatch } from "react"; import { type IUserStudyChapter, useLichess } from "#/hooks/useLichess.ts"; +import type { GameAction } from "#/reducers/gameReducer.ts"; interface IProps { selectedStudyId: string; - gameDispatch: any; + gameDispatch: Dispatch; } const SelectStudyChapter = ({ selectedStudyId, gameDispatch }: IProps) => { @@ -23,7 +24,7 @@ const SelectStudyChapter = ({ selectedStudyId, gameDispatch }: IProps) => { const handleChapterClick = async (chapter: IUserStudyChapter) => { const { headers, pgn } = await loadLichessStudyChapter({ chapter }); - gameDispatch({ type: "SET_PGN", payload: headers, pgn }); + gameDispatch({ type: "SET_GAME", payload: { pgn, headers } }); setIsOpen(false); }; diff --git a/src/hooks/useLichess.ts b/src/hooks/useLichess.ts index 1958977..be58284 100644 --- a/src/hooks/useLichess.ts +++ b/src/hooks/useLichess.ts @@ -2,7 +2,6 @@ import { useNavigate } from "@tanstack/react-router"; import { useServerFn } from "@tanstack/react-start"; import { useEffect, useState } from "react"; import { useLichessUser } from "#/context/LichessUserContext.tsx"; -import { useChessGame } from "#/hooks/useChessGame.ts"; import { getSession, getStudyChapters, @@ -138,7 +137,6 @@ export const useLichess = () => { author: "", }; - console.log(headers, pgn); return { headers, pgn }; }; diff --git a/src/reducers/gameReducer.ts b/src/reducers/gameReducer.ts index db97788..755427e 100644 --- a/src/reducers/gameReducer.ts +++ b/src/reducers/gameReducer.ts @@ -1,6 +1,6 @@ import type { IGameState, IHeader, IPosition } from "#/interfaces.ts"; -type GameAction = +export type GameAction = | { type: "SET_GAME"; payload: { pgn: string; headers: IHeader } } | { type: "CLEAR_GAME" } | { type: "SET_HEADERS"; payload: IHeader }