style : fix gap & margin & padding

This commit is contained in:
GuillaumeSD
2024-02-25 02:13:06 +01:00
parent 892004f0d0
commit 8d15b7e1a2
15 changed files with 104 additions and 119 deletions

View File

@@ -28,12 +28,7 @@ export default function Slider({
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
> >
<Typography <Typography id={`input-${label}`} textAlign="left" width="100%">
id={`input-${label}`}
gutterBottom
textAlign="left"
width="100%"
>
{label} {label}
</Typography> </Typography>

View File

@@ -1,24 +1,19 @@
import { import {
boardAtom, boardAtom,
currentMoveAtom,
engineDepthAtom, engineDepthAtom,
engineMultiPvAtom, engineMultiPvAtom,
gameAtom, gameAtom,
gameEvalAtom, gameEvalAtom,
} from "@/sections/analysis/states"; } from "@/sections/analysis/states";
import { MoveEval } from "@/types/eval"; import { CurrentMove, MoveEval } from "@/types/eval";
import { Move } from "chess.js"; import { useAtom, useAtomValue } from "jotai";
import { useAtomValue } from "jotai"; import { useEffect } from "react";
import { useEffect, useState } from "react";
import { useEngine } from "./useEngine"; import { useEngine } from "./useEngine";
import { EngineName } from "@/types/enums"; import { EngineName } from "@/types/enums";
export type CurrentMove = Partial<Move> & {
eval?: MoveEval;
lastEval?: MoveEval;
};
export const useCurrentMove = (engineName?: EngineName) => { export const useCurrentMove = (engineName?: EngineName) => {
const [currentMove, setCurrentMove] = useState<CurrentMove>({}); const [currentMove, setCurrentMove] = useAtom(currentMoveAtom);
const engine = useEngine(engineName); const engine = useEngine(engineName);
const gameEval = useAtomValue(gameEvalAtom); const gameEval = useAtomValue(gameEvalAtom);
const game = useAtomValue(gameAtom); const game = useAtomValue(gameAtom);

View File

@@ -97,11 +97,12 @@ export const getEvaluationBarValue = (
const cp = bestLine.cp; const cp = bestLine.cp;
const whiteBarPercentage = Math.min(50 + cp / 20, 98); 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) { 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) };
}; };

View File

@@ -2,14 +2,16 @@ import { useChessActions } from "@/hooks/useChess";
import Board from "@/sections/analysis/board"; import Board from "@/sections/analysis/board";
import ReviewPanelBody from "@/sections/analysis/reviewPanelBody"; import ReviewPanelBody from "@/sections/analysis/reviewPanelBody";
import ReviewPanelHeader from "@/sections/analysis/reviewPanelHeader"; import ReviewPanelHeader from "@/sections/analysis/reviewPanelHeader";
import AnalyzePanel from "@/sections/analysis/reviewPanelHeader/analyzePanel";
import ReviewPanelToolBar from "@/sections/analysis/reviewPanelToolbar"; import ReviewPanelToolBar from "@/sections/analysis/reviewPanelToolbar";
import ArrowOptions from "@/sections/analysis/reviewPanelToolbar/arrowOptions";
import { import {
boardAtom, boardAtom,
boardOrientationAtom, boardOrientationAtom,
gameAtom, gameAtom,
gameEvalAtom, gameEvalAtom,
} from "@/sections/analysis/states"; } from "@/sections/analysis/states";
import { Grid } from "@mui/material"; import { Divider, Grid } from "@mui/material";
import { Chess } from "chess.js"; import { Chess } from "chess.js";
import { useSetAtom } from "jotai"; import { useSetAtom } from "jotai";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
@@ -35,9 +37,9 @@ export default function GameReport() {
return ( return (
<Grid <Grid
container container
rowGap={2} rowGap={6}
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="start"
marginTop={1} marginTop={1}
> >
<Grid <Grid
@@ -46,7 +48,8 @@ export default function GameReport() {
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
xs={12} xs={12}
md={6} md={9}
lg={6}
> >
<Board /> <Board />
</Grid> </Grid>
@@ -54,7 +57,6 @@ export default function GameReport() {
<Grid <Grid
item item
container container
rowGap={2}
paddingLeft={{ xs: 0, lg: 6 }} paddingLeft={{ xs: 0, lg: 6 }}
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
@@ -64,8 +66,6 @@ export default function GameReport() {
<Grid <Grid
container container
item item
rowGap={3}
columnGap={1}
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
borderRadius={2} borderRadius={2}
@@ -74,17 +74,27 @@ export default function GameReport() {
xs={12} xs={12}
sx={{ sx={{
backgroundColor: "secondary.main", backgroundColor: "secondary.main",
borderRadius: 2,
borderColor: "primary.main", borderColor: "primary.main",
borderWidth: 2, borderWidth: 2,
}} }}
paddingY={3} padding={3}
gap={4}
> >
<ReviewPanelHeader /> <ReviewPanelHeader />
<Divider sx={{ width: "90%" }} />
<AnalyzePanel />
<Divider sx={{ width: "90%" }} />
<ReviewPanelBody /> <ReviewPanelBody />
<Divider sx={{ width: "90%" }} />
<ReviewPanelToolBar /> <ReviewPanelToolBar />
<ArrowOptions />
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>

View File

@@ -1,12 +1,11 @@
import { Box, Grid, Typography } from "@mui/material"; import { Box, Grid, Typography } from "@mui/material";
import { useAtomValue } from "jotai"; import { useAtomValue } from "jotai";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { boardAtom, boardOrientationAtom } from "../states"; import { boardAtom, boardOrientationAtom, currentMoveAtom } from "../states";
import { getEvaluationBarValue } from "@/lib/chess"; import { getEvaluationBarValue } from "@/lib/chess";
import { useCurrentMove } from "@/hooks/useCurrentMove";
interface Props { interface Props {
height?: number; height: number;
} }
export default function EvaluationBar({ height }: Props) { export default function EvaluationBar({ height }: Props) {
@@ -16,7 +15,7 @@ export default function EvaluationBar({ height }: Props) {
}); });
const board = useAtomValue(boardAtom); const board = useAtomValue(boardAtom);
const boardOrientation = useAtomValue(boardOrientationAtom); const boardOrientation = useAtomValue(boardOrientationAtom);
const currentMove = useCurrentMove(); const currentMove = useAtomValue(currentMoveAtom);
useEffect(() => { useEffect(() => {
const bestLine = currentMove?.eval?.lines[0]; const bestLine = currentMove?.eval?.lines[0];
@@ -32,12 +31,11 @@ export default function EvaluationBar({ height }: Props) {
container container
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
xs={1} width="2rem"
height={height} height={height}
paddingX={3}
> >
<Box <Box
sx={{ backgroundColor: boardOrientation ? "black" : "white" }} sx={{ backgroundColor: boardOrientation ? "secondary.main" : "white" }}
height={`${ height={`${
boardOrientation boardOrientation
? 100 - evalBar.whiteBarPercentage ? 100 - evalBar.whiteBarPercentage
@@ -59,7 +57,7 @@ export default function EvaluationBar({ height }: Props) {
</Box> </Box>
<Box <Box
sx={{ backgroundColor: boardOrientation ? "white" : "black" }} sx={{ backgroundColor: boardOrientation ? "white" : "secondary.main" }}
height={`${ height={`${
boardOrientation boardOrientation
? evalBar.whiteBarPercentage ? evalBar.whiteBarPercentage

View File

@@ -4,12 +4,12 @@ import { useAtomValue } from "jotai";
import { import {
boardAtom, boardAtom,
boardOrientationAtom, boardOrientationAtom,
currentMoveAtom,
showBestMoveArrowAtom, showBestMoveArrowAtom,
showPlayerMoveArrowAtom, showPlayerMoveArrowAtom,
} from "../states"; } from "../states";
import { Arrow, Square } from "react-chessboard/dist/chessboard/types"; import { Arrow, Square } from "react-chessboard/dist/chessboard/types";
import { useChessActions } from "@/hooks/useChess"; import { useChessActions } from "@/hooks/useChess";
import { useCurrentMove } from "@/hooks/useCurrentMove";
import { useMemo, useRef } from "react"; import { useMemo, useRef } from "react";
import PlayerInfo from "./playerInfo"; import PlayerInfo from "./playerInfo";
import EvaluationBar from "./evaluationBar"; import EvaluationBar from "./evaluationBar";
@@ -21,7 +21,7 @@ export default function Board() {
const showBestMoveArrow = useAtomValue(showBestMoveArrowAtom); const showBestMoveArrow = useAtomValue(showBestMoveArrowAtom);
const showPlayerMoveArrow = useAtomValue(showPlayerMoveArrowAtom); const showPlayerMoveArrow = useAtomValue(showPlayerMoveArrowAtom);
const boardActions = useChessActions(boardAtom); const boardActions = useChessActions(boardAtom);
const currentMove = useCurrentMove(); const currentMove = useAtomValue(currentMoveAtom);
const onPieceDrop = (source: Square, target: Square): boolean => { const onPieceDrop = (source: Square, target: Square): boolean => {
try { try {
@@ -71,16 +71,24 @@ export default function Board() {
}, [currentMove, showBestMoveArrow, showPlayerMoveArrow]); }, [currentMove, showBestMoveArrow, showPlayerMoveArrow]);
return ( return (
<Grid item container justifyContent="center" alignItems="center" xs={12}> <Grid
<EvaluationBar height={boardRef?.current?.offsetWidth} /> item
container
justifyContent="center"
alignItems="center"
xs={12}
wrap="nowrap"
>
<EvaluationBar height={boardRef?.current?.offsetHeight || 800} />
<Grid <Grid
item item
container container
rowGap={2} rowGap={1}
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
xs={11} paddingLeft={2}
xs
> >
<PlayerInfo color={boardOrientation ? "black" : "white"} /> <PlayerInfo color={boardOrientation ? "black" : "white"} />
@@ -90,6 +98,7 @@ export default function Board() {
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
ref={boardRef} ref={boardRef}
xs={12}
> >
<Chessboard <Chessboard
id="AnalysisBoard" id="AnalysisBoard"

View File

@@ -16,15 +16,8 @@ export default function PlayerInfo({ color }: Props) {
game.header()[color === "white" ? "White" : "Black"]; game.header()[color === "white" ? "White" : "Black"];
return ( return (
<Grid <Grid item container xs={12} justifyContent="center" alignItems="center">
item <Typography variant="h5">
container
xs={12}
justifyContent="center"
alignItems="center"
gap={1}
>
<Typography variant="h4">
{playerName || (color === "white" ? "White" : "Black")} {playerName || (color === "white" ? "White" : "Black")}
</Typography> </Typography>
</Grid> </Grid>

View File

@@ -1,5 +1,5 @@
import { Icon } from "@iconify/react"; 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 { useAtomValue } from "jotai";
import { boardAtom, engineMultiPvAtom, gameAtom } from "./states"; import { boardAtom, engineMultiPvAtom, gameAtom } from "./states";
import LineEvaluation from "./lineEvaluation"; import LineEvaluation from "./lineEvaluation";
@@ -29,9 +29,14 @@ export default function ReviewPanelBody() {
: linesSkeleton; : linesSkeleton;
return ( return (
<> <Grid
<Divider sx={{ width: "90%", marginY: 3 }} /> item
container
xs={12}
justifyContent="center"
alignItems="center"
gap={2}
>
<Grid <Grid
item item
container container
@@ -73,6 +78,6 @@ export default function ReviewPanelBody() {
))} ))}
</List> </List>
</Grid> </Grid>
</> </Grid>
); );
} }

View File

@@ -57,7 +57,7 @@ export default function AnalyzePanel() {
xs={12} xs={12}
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
rowGap={4} rowGap={3}
> >
<Slider <Slider
label="Maximum depth" label="Maximum depth"
@@ -75,14 +75,7 @@ export default function AnalyzePanel() {
xs={6} xs={6}
/> />
<Grid <Grid item container xs={12} justifyContent="center" alignItems="center">
item
container
xs={12}
justifyContent="center"
alignItems="center"
marginTop={1}
>
<LoadingButton <LoadingButton
variant="contained" variant="contained"
size="large" size="large"

View File

@@ -12,14 +12,7 @@ export default function GamePanel() {
if (!hasGameInfo) { if (!hasGameInfo) {
return ( return (
<Grid <Grid item container xs={12} justifyContent="center" alignItems="center">
item
container
xs={12}
justifyContent="center"
alignItems="center"
marginY={1}
>
<Typography variant="h6">No game loaded</Typography> <Typography variant="h6">No game loaded</Typography>
</Grid> </Grid>
); );
@@ -32,8 +25,7 @@ export default function GamePanel() {
xs={12} xs={12}
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
gap={3} gap={2}
marginY={1}
> >
<Grid item container xs={12} justifyContent="center" alignItems="center"> <Grid item container xs={12} justifyContent="center" alignItems="center">
<PlayerInfo color="white" /> <PlayerInfo color="white" />
@@ -51,7 +43,7 @@ export default function GamePanel() {
xs={10} xs={10}
justifyContent="space-evenly" justifyContent="space-evenly"
alignItems="center" alignItems="center"
gap={3} gap={2}
> >
<Typography> <Typography>
Site : {gameFromUrl?.site || game.header().Site || "?"} Site : {gameFromUrl?.site || game.header().Site || "?"}

View File

@@ -1,6 +1,5 @@
import { Icon } from "@iconify/react"; import { Icon } from "@iconify/react";
import { Divider, Grid, Typography } from "@mui/material"; import { Grid, Typography } from "@mui/material";
import AnalyzePanel from "./analyzePanel";
import GamePanel from "./gamePanel"; import GamePanel from "./gamePanel";
import LoadGame from "./loadGame"; import LoadGame from "./loadGame";
@@ -34,15 +33,11 @@ export default function ReviewPanelHeader() {
xs={12} xs={12}
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
gap={4} gap={3}
> >
<GamePanel /> <GamePanel />
<LoadGame /> <LoadGame />
</Grid> </Grid>
<Divider sx={{ width: "90%", marginY: 3 }} />
<AnalyzePanel />
</Grid> </Grid>
); );
} }

View File

@@ -18,7 +18,6 @@ export default function ArrowOptions() {
justifyContent="space-evenly" justifyContent="space-evenly"
alignItems="center" alignItems="center"
xs={12} xs={12}
marginY={3}
gap={3} gap={3}
> >
<FormControlLabel <FormControlLabel

View File

@@ -1,4 +1,4 @@
import { Divider, Grid, IconButton, Tooltip } from "@mui/material"; import { Grid, IconButton, Tooltip } from "@mui/material";
import { Icon } from "@iconify/react"; import { Icon } from "@iconify/react";
import { useAtomValue } from "jotai"; import { useAtomValue } from "jotai";
import { boardAtom } from "../states"; import { boardAtom } from "../states";
@@ -7,7 +7,6 @@ import FlipBoardButton from "./flipBoardButton";
import NextMoveButton from "./nextMoveButton"; import NextMoveButton from "./nextMoveButton";
import GoToLastPositionButton from "./goToLastPositionButton"; import GoToLastPositionButton from "./goToLastPositionButton";
import SaveButton from "./saveButton"; import SaveButton from "./saveButton";
import ArrowOptions from "./arrowOptions";
export default function ReviewPanelToolBar() { export default function ReviewPanelToolBar() {
const board = useAtomValue(boardAtom); const board = useAtomValue(boardAtom);
@@ -16,42 +15,36 @@ export default function ReviewPanelToolBar() {
const boardHistory = board.history(); const boardHistory = board.history();
return ( return (
<> <Grid container item justifyContent="center" alignItems="center" xs={12}>
<Divider sx={{ width: "90%", marginY: 3 }} /> <FlipBoardButton />
<Grid container item justifyContent="center" alignItems="center" xs={12}> <Tooltip title="Reset board">
<FlipBoardButton /> <Grid>
<IconButton
onClick={() => boardActions.reset()}
disabled={boardHistory.length === 0}
>
<Icon icon="ri:skip-back-line" />
</IconButton>
</Grid>
</Tooltip>
<Tooltip title="Reset board"> <Tooltip title="Go to previous move">
<Grid> <Grid>
<IconButton <IconButton
onClick={() => boardActions.reset()} onClick={() => boardActions.undo()}
disabled={boardHistory.length === 0} disabled={boardHistory.length === 0}
> >
<Icon icon="ri:skip-back-line" /> <Icon icon="ri:arrow-left-s-line" height={30} />
</IconButton> </IconButton>
</Grid> </Grid>
</Tooltip> </Tooltip>
<Tooltip title="Go to previous move"> <NextMoveButton />
<Grid>
<IconButton
onClick={() => boardActions.undo()}
disabled={boardHistory.length === 0}
>
<Icon icon="ri:arrow-left-s-line" height={30} />
</IconButton>
</Grid>
</Tooltip>
<NextMoveButton /> <GoToLastPositionButton />
<GoToLastPositionButton /> <SaveButton />
</Grid>
<SaveButton />
</Grid>
<ArrowOptions />
</>
); );
} }

View File

@@ -1,10 +1,11 @@
import { GameEval } from "@/types/eval"; import { CurrentMove, GameEval } from "@/types/eval";
import { Chess } from "chess.js"; import { Chess } from "chess.js";
import { atom } from "jotai"; import { atom } from "jotai";
export const gameEvalAtom = atom<GameEval | undefined>(undefined); export const gameEvalAtom = atom<GameEval | undefined>(undefined);
export const gameAtom = atom(new Chess()); export const gameAtom = atom(new Chess());
export const boardAtom = atom(new Chess()); export const boardAtom = atom(new Chess());
export const currentMoveAtom = atom<CurrentMove>({});
export const boardOrientationAtom = atom(true); export const boardOrientationAtom = atom(true);
export const showBestMoveArrowAtom = atom(true); export const showBestMoveArrowAtom = atom(true);

View File

@@ -1,3 +1,4 @@
import { Move } from "chess.js";
import { EngineName } from "./enums"; import { EngineName } from "./enums";
export interface MoveEval { export interface MoveEval {
@@ -37,3 +38,8 @@ export interface EvaluatePositionWithUpdateParams {
multiPv?: number; multiPv?: number;
setPartialEval: (moveEval: MoveEval) => void; setPartialEval: (moveEval: MoveEval) => void;
} }
export type CurrentMove = Partial<Move> & {
eval?: MoveEval;
lastEval?: MoveEval;
};