mirror of
https://github.com/TheRealOwenRees/chess-scribe-website.git
synced 2026-07-23 01:46:57 +00:00
39 lines
679 B
TypeScript
39 lines
679 B
TypeScript
interface IDiagrams {
|
|
ply: number;
|
|
fen: string;
|
|
}
|
|
|
|
export interface IGameState {
|
|
pgn: string;
|
|
headers: string;
|
|
diagrams: IDiagrams[];
|
|
diagramClock: boolean;
|
|
}
|
|
|
|
type GameAction =
|
|
| { type: "SET_GAME"; payload: { pgn: string; headers: "" } }
|
|
| { type: "CLEAR_GAME" };
|
|
|
|
export const initialGameState = {
|
|
pgn: "",
|
|
headers: "",
|
|
diagrams: [],
|
|
diagramClock: false,
|
|
};
|
|
|
|
export const gameReducer = (state: IGameState, action: GameAction) => {
|
|
switch (action.type) {
|
|
case "SET_GAME":
|
|
return {
|
|
pgn: action.payload.pgn,
|
|
headers: "",
|
|
diagrams: [],
|
|
diagramClock: false,
|
|
};
|
|
case "CLEAR_GAME":
|
|
return initialGameState;
|
|
default:
|
|
return state;
|
|
}
|
|
};
|