From 3757d0cf9a0f5bd89dbfc825d7472fcfc30fe57e Mon Sep 17 00:00:00 2001 From: Paul Hutchinson Date: Tue, 9 Dec 2025 11:24:05 +0000 Subject: [PATCH 1/2] Fix bug with board rendering --- lichess.ts | 8 +++--- pages/_document.tsx | 2 +- pages/hardcoded.tsx | 67 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 pages/hardcoded.tsx diff --git a/lichess.ts b/lichess.ts index c1a6cdb..5f4a208 100644 --- a/lichess.ts +++ b/lichess.ts @@ -177,13 +177,13 @@ export default function processGame(game: Game, username: string, settings: Sett const chess = new Chess(undefined, { skipValidation: true }); chess.loadPgn(game.pgn); - const turn = chess.turn(); - while (chess.moveNumber() > 1 && (chess.moveNumber() - 1) * 2 + Number(turn === 'b') > plyOfInterest) { + while (chess.moveNumber() > 1 + && (chess.moveNumber() - 1) * 2 + Number(chess.turn() === 'b') > plyOfInterest) { chess.undo(); } const board = chess.board(); - if (turn === 'b') { + if (chess.turn() === 'b') { board.reverse(); board.map(row => row.reverse()); } @@ -205,7 +205,7 @@ export default function processGame(game: Game, username: string, settings: Sett board: { grid: board, ply: plyOfInterest - 1, - turn, + turn: chess.turn(), }, analysis: game.analysis?.map(entry => ({ eval: entry.eval, diff --git a/pages/_document.tsx b/pages/_document.tsx index c2164c8..654461d 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -44,7 +44,7 @@ export default function Document() { - + diff --git a/pages/hardcoded.tsx b/pages/hardcoded.tsx new file mode 100644 index 0000000..a88d502 --- /dev/null +++ b/pages/hardcoded.tsx @@ -0,0 +1,67 @@ +import Book from "../components/Book"; +import type { Game, Settings, User } from "../types"; +import type { Game as LichessGame } from "../lichess"; +import Head from "next/head"; +import useTranslation from "next-translate/useTranslation"; +import gamesSource from '../jo55.json'; +import processGame from "../lichess"; + +const games = gamesSource as LichessGame[]; + +export default function HomePage() { + const settings: Settings = { + pageSize: "A4", + color: "all", + result: "all", + gameType: "all", + rated: "rated", + analysed: "all", + dateRange: "all", + }; + const user: User = { + name: 'Jo55', + rating: 1921, + ratingProvisional: false, + title: 'IM', + }; + const data: { user: User, games: Game[], settings: Settings } = { + user, + games: games + .filter((game, i) => game.analysis !== undefined) + .filter((game, i) => i === 80) + .map((game) => processGame(game, "jo55", settings)) + .filter((game): game is Game => + game !== undefined + && game.movesCount > 10 + && (game.white.rating + game.black.rating) > 3000 + && game.analysis !== undefined + ) + .sort((a, b) => (a.white.rating + a.black.rating > b.white.rating + b.black.rating ? -1 : 1)), + settings, + }; + const { t } = useTranslation("common"); + + return <> + + Me Chess Book + +
+ +
+ {/*

{data.games.length} games

*/} + {data.games.map((game, i) => ( +
+ https://lichess.org/{game.id} +
+ ))} + + ; +} From c5b6950d0ba536eed00b093a74887dd78e6de3c1 Mon Sep 17 00:00:00 2001 From: Paul Hutchinson Date: Tue, 9 Dec 2025 11:25:48 +0000 Subject: [PATCH 2/2] Remove test file --- pages/hardcoded.tsx | 67 --------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 pages/hardcoded.tsx diff --git a/pages/hardcoded.tsx b/pages/hardcoded.tsx deleted file mode 100644 index a88d502..0000000 --- a/pages/hardcoded.tsx +++ /dev/null @@ -1,67 +0,0 @@ -import Book from "../components/Book"; -import type { Game, Settings, User } from "../types"; -import type { Game as LichessGame } from "../lichess"; -import Head from "next/head"; -import useTranslation from "next-translate/useTranslation"; -import gamesSource from '../jo55.json'; -import processGame from "../lichess"; - -const games = gamesSource as LichessGame[]; - -export default function HomePage() { - const settings: Settings = { - pageSize: "A4", - color: "all", - result: "all", - gameType: "all", - rated: "rated", - analysed: "all", - dateRange: "all", - }; - const user: User = { - name: 'Jo55', - rating: 1921, - ratingProvisional: false, - title: 'IM', - }; - const data: { user: User, games: Game[], settings: Settings } = { - user, - games: games - .filter((game, i) => game.analysis !== undefined) - .filter((game, i) => i === 80) - .map((game) => processGame(game, "jo55", settings)) - .filter((game): game is Game => - game !== undefined - && game.movesCount > 10 - && (game.white.rating + game.black.rating) > 3000 - && game.analysis !== undefined - ) - .sort((a, b) => (a.white.rating + a.black.rating > b.white.rating + b.black.rating ? -1 : 1)), - settings, - }; - const { t } = useTranslation("common"); - - return <> - - Me Chess Book - -
- -
- {/*

{data.games.length} games

*/} - {data.games.map((game, i) => ( -
- https://lichess.org/{game.id} -
- ))} - - ; -}