diff --git a/src/components/slider.tsx b/src/components/slider.tsx index 7b4157f..31c728b 100644 --- a/src/components/slider.tsx +++ b/src/components/slider.tsx @@ -28,12 +28,7 @@ export default function Slider({ justifyContent="center" alignItems="center" > - + {label} diff --git a/src/hooks/useCurrentMove.ts b/src/hooks/useCurrentMove.ts index f4387ba..b6dc3b6 100644 --- a/src/hooks/useCurrentMove.ts +++ b/src/hooks/useCurrentMove.ts @@ -1,24 +1,19 @@ import { boardAtom, + currentMoveAtom, engineDepthAtom, engineMultiPvAtom, gameAtom, gameEvalAtom, } from "@/sections/analysis/states"; -import { MoveEval } from "@/types/eval"; -import { Move } from "chess.js"; -import { useAtomValue } from "jotai"; -import { useEffect, useState } from "react"; +import { CurrentMove, MoveEval } from "@/types/eval"; +import { useAtom, useAtomValue } from "jotai"; +import { useEffect } from "react"; import { useEngine } from "./useEngine"; import { EngineName } from "@/types/enums"; -export type CurrentMove = Partial & { - eval?: MoveEval; - lastEval?: MoveEval; -}; - export const useCurrentMove = (engineName?: EngineName) => { - const [currentMove, setCurrentMove] = useState({}); + const [currentMove, setCurrentMove] = useAtom(currentMoveAtom); const engine = useEngine(engineName); const gameEval = useAtomValue(gameEvalAtom); const game = useAtomValue(gameAtom); diff --git a/src/lib/chess.ts b/src/lib/chess.ts index 8a172d6..a5320f8 100644 --- a/src/lib/chess.ts +++ b/src/lib/chess.ts @@ -97,11 +97,12 @@ export const getEvaluationBarValue = ( const cp = bestLine.cp; const whiteBarPercentage = Math.min(50 + cp / 20, 98); - const label = (cp / 100).toFixed(1); + const pEval = Math.abs(cp) / 100; + const label = pEval.toFixed(1); if (label.toString().length > 3) { - return { whiteBarPercentage, label: (cp / 100).toFixed(0) }; + return { whiteBarPercentage, label: pEval.toFixed(0) }; } - return { whiteBarPercentage, label: (cp / 100).toFixed(1) }; + return { whiteBarPercentage, label: pEval.toFixed(1) }; }; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 8d1d3aa..855154a 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -2,14 +2,16 @@ import { useChessActions } from "@/hooks/useChess"; import Board from "@/sections/analysis/board"; import ReviewPanelBody from "@/sections/analysis/reviewPanelBody"; import ReviewPanelHeader from "@/sections/analysis/reviewPanelHeader"; +import AnalyzePanel from "@/sections/analysis/reviewPanelHeader/analyzePanel"; import ReviewPanelToolBar from "@/sections/analysis/reviewPanelToolbar"; +import ArrowOptions from "@/sections/analysis/reviewPanelToolbar/arrowOptions"; import { boardAtom, boardOrientationAtom, gameAtom, gameEvalAtom, } from "@/sections/analysis/states"; -import { Grid } from "@mui/material"; +import { Divider, Grid } from "@mui/material"; import { Chess } from "chess.js"; import { useSetAtom } from "jotai"; import { useRouter } from "next/router"; @@ -35,9 +37,9 @@ export default function GameReport() { return ( @@ -54,7 +57,6 @@ export default function GameReport() { + + + + + + + + + + diff --git a/src/sections/analysis/board/evaluationBar.tsx b/src/sections/analysis/board/evaluationBar.tsx index c0db893..61298dd 100644 --- a/src/sections/analysis/board/evaluationBar.tsx +++ b/src/sections/analysis/board/evaluationBar.tsx @@ -1,12 +1,11 @@ import { Box, Grid, Typography } from "@mui/material"; import { useAtomValue } from "jotai"; import { useEffect, useState } from "react"; -import { boardAtom, boardOrientationAtom } from "../states"; +import { boardAtom, boardOrientationAtom, currentMoveAtom } from "../states"; import { getEvaluationBarValue } from "@/lib/chess"; -import { useCurrentMove } from "@/hooks/useCurrentMove"; interface Props { - height?: number; + height: number; } export default function EvaluationBar({ height }: Props) { @@ -16,7 +15,7 @@ export default function EvaluationBar({ height }: Props) { }); const board = useAtomValue(boardAtom); const boardOrientation = useAtomValue(boardOrientationAtom); - const currentMove = useCurrentMove(); + const currentMove = useAtomValue(currentMoveAtom); useEffect(() => { const bestLine = currentMove?.eval?.lines[0]; @@ -32,12 +31,11 @@ export default function EvaluationBar({ height }: Props) { container justifyContent="center" alignItems="center" - xs={1} + width="2rem" height={height} - paddingX={3} > { try { @@ -71,16 +71,24 @@ export default function Board() { }, [currentMove, showBestMoveArrow, showPlayerMoveArrow]); return ( - - + + @@ -90,6 +98,7 @@ export default function Board() { justifyContent="center" alignItems="center" ref={boardRef} + xs={12} > - + + {playerName || (color === "white" ? "White" : "Black")} diff --git a/src/sections/analysis/reviewPanelBody.tsx b/src/sections/analysis/reviewPanelBody.tsx index a31bdc8..63641bb 100644 --- a/src/sections/analysis/reviewPanelBody.tsx +++ b/src/sections/analysis/reviewPanelBody.tsx @@ -1,5 +1,5 @@ import { Icon } from "@iconify/react"; -import { Divider, Grid, List, Typography } from "@mui/material"; +import { Grid, List, Typography } from "@mui/material"; import { useAtomValue } from "jotai"; import { boardAtom, engineMultiPvAtom, gameAtom } from "./states"; import LineEvaluation from "./lineEvaluation"; @@ -29,9 +29,14 @@ export default function ReviewPanelBody() { : linesSkeleton; return ( - <> - - + - + ); } diff --git a/src/sections/analysis/reviewPanelHeader/analyzePanel.tsx b/src/sections/analysis/reviewPanelHeader/analyzePanel.tsx index 8f07eb4..7ccc042 100644 --- a/src/sections/analysis/reviewPanelHeader/analyzePanel.tsx +++ b/src/sections/analysis/reviewPanelHeader/analyzePanel.tsx @@ -57,7 +57,7 @@ export default function AnalyzePanel() { xs={12} justifyContent="center" alignItems="center" - rowGap={4} + rowGap={3} > - + + No game loaded ); @@ -32,8 +25,7 @@ export default function GamePanel() { xs={12} justifyContent="center" alignItems="center" - gap={3} - marginY={1} + gap={2} > @@ -51,7 +43,7 @@ export default function GamePanel() { xs={10} justifyContent="space-evenly" alignItems="center" - gap={3} + gap={2} > Site : {gameFromUrl?.site || game.header().Site || "?"} diff --git a/src/sections/analysis/reviewPanelHeader/index.tsx b/src/sections/analysis/reviewPanelHeader/index.tsx index 7bc1536..09f63e1 100644 --- a/src/sections/analysis/reviewPanelHeader/index.tsx +++ b/src/sections/analysis/reviewPanelHeader/index.tsx @@ -1,6 +1,5 @@ import { Icon } from "@iconify/react"; -import { Divider, Grid, Typography } from "@mui/material"; -import AnalyzePanel from "./analyzePanel"; +import { Grid, Typography } from "@mui/material"; import GamePanel from "./gamePanel"; import LoadGame from "./loadGame"; @@ -34,15 +33,11 @@ export default function ReviewPanelHeader() { xs={12} justifyContent="center" alignItems="center" - gap={4} + gap={3} > - - - - ); } diff --git a/src/sections/analysis/reviewPanelToolbar/arrowOptions.tsx b/src/sections/analysis/reviewPanelToolbar/arrowOptions.tsx index 5f4d43c..a5c5d76 100644 --- a/src/sections/analysis/reviewPanelToolbar/arrowOptions.tsx +++ b/src/sections/analysis/reviewPanelToolbar/arrowOptions.tsx @@ -18,7 +18,6 @@ export default function ArrowOptions() { justifyContent="space-evenly" alignItems="center" xs={12} - marginY={3} gap={3} > - + + - - + + + boardActions.reset()} + disabled={boardHistory.length === 0} + > + + + + - - - boardActions.reset()} - disabled={boardHistory.length === 0} - > - - - - + + + boardActions.undo()} + disabled={boardHistory.length === 0} + > + + + + - - - boardActions.undo()} - disabled={boardHistory.length === 0} - > - - - - + - + - - - - - - - + + ); } diff --git a/src/sections/analysis/states.ts b/src/sections/analysis/states.ts index 9b2afa4..cb8cd77 100644 --- a/src/sections/analysis/states.ts +++ b/src/sections/analysis/states.ts @@ -1,10 +1,11 @@ -import { GameEval } from "@/types/eval"; +import { CurrentMove, GameEval } from "@/types/eval"; import { Chess } from "chess.js"; import { atom } from "jotai"; export const gameEvalAtom = atom(undefined); export const gameAtom = atom(new Chess()); export const boardAtom = atom(new Chess()); +export const currentMoveAtom = atom({}); export const boardOrientationAtom = atom(true); export const showBestMoveArrowAtom = atom(true); diff --git a/src/types/eval.ts b/src/types/eval.ts index 60637e4..7c14d18 100644 --- a/src/types/eval.ts +++ b/src/types/eval.ts @@ -1,3 +1,4 @@ +import { Move } from "chess.js"; import { EngineName } from "./enums"; export interface MoveEval { @@ -37,3 +38,8 @@ export interface EvaluatePositionWithUpdateParams { multiPv?: number; setPartialEval: (moveEval: MoveEval) => void; } + +export type CurrentMove = Partial & { + eval?: MoveEval; + lastEval?: MoveEval; +};