feat : show eval

This commit is contained in:
GuillaumeSD
2024-02-17 19:58:00 +01:00
parent 770ae13517
commit 98d99c0df0
10 changed files with 224 additions and 50 deletions

View File

@@ -1,21 +1,26 @@
import { drawBoard } from "@/lib/board";
import { drawEvaluationBar } from "@/lib/evalBar";
import { useAtomValue } from "jotai";
import { useEffect, useRef } from "react";
import { boardPgnAtom } from "./index.state";
import { getLastFen } from "@/lib/chess";
export default function Board() {
const boardRef = useRef<HTMLCanvasElement>(null);
const evalBarRef = useRef<HTMLCanvasElement>(null);
const boardPgn = useAtomValue(boardPgnAtom);
const boardFen = getLastFen(boardPgn);
useEffect(() => {
const ctx = boardRef.current?.getContext("2d");
if (!ctx) return;
drawBoard(ctx);
drawBoard(ctx, boardFen);
const evalCtx = evalBarRef.current?.getContext("2d");
if (!evalCtx) return;
drawEvaluationBar(evalCtx);
}, []);
}, [boardFen]);
return (
<div id="board-outer-container" className="center">