fix : UI flickering

This commit is contained in:
GuillaumeSD
2024-02-26 19:40:55 +01:00
parent 525f68f1fd
commit d5d1363da1
7 changed files with 35 additions and 21 deletions

View File

@@ -39,12 +39,12 @@ export const useScreenSize = () => {
const width = screenSize.width; const width = screenSize.width;
const height = screenSize.height; const height = screenSize.height;
// 900 is the md layout breakpoint // 1200 is the lg layout breakpoint
if (width < 900) { if (window?.innerWidth < 1200) {
return Math.min(width, height) * 0.95; return Math.min(width, height - 150);
} }
return Math.min(width - 500, height) * 0.95; return Math.min(width - 600, height);
}; };
return { ...screenSize, boardSize: getBoardSize() }; return { ...screenSize, boardSize: getBoardSize() };

View File

@@ -85,8 +85,8 @@ export const getEvaluationBarValue = (
): { whiteBarPercentage: number; label: string } => { ): { whiteBarPercentage: number; label: string } => {
if (bestLine.mate) { if (bestLine.mate) {
return { return {
whiteBarPercentage: whiteToPlay ? 100 : 0, whiteBarPercentage: whiteToPlay && bestLine.mate > 0 ? 100 : 0,
label: `M${bestLine.mate}`, label: `M${Math.abs(bestLine.mate)}`,
}; };
} }

View File

@@ -207,6 +207,7 @@ export abstract class UciEngine {
parsedResults.lines = parsedResults.lines.map((line) => ({ parsedResults.lines = parsedResults.lines.map((line) => ({
...line, ...line,
cp: line.cp ? -line.cp : line.cp, cp: line.cp ? -line.cp : line.cp,
mate: line.mate ? -line.mate : line.mate,
})); }));
} }

View File

@@ -17,7 +17,7 @@ import { useEffect } from "react";
export default function GameReport() { export default function GameReport() {
const theme = useTheme(); const theme = useTheme();
const isMdOrGreater = useMediaQuery(theme.breakpoints.up("md")); const isLgOrGreater = useMediaQuery(theme.breakpoints.up("lg"));
const { reset: resetBoard } = useChessActions(boardAtom); const { reset: resetBoard } = useChessActions(boardAtom);
const { setPgn: setGamePgn } = useChessActions(gameAtom); const { setPgn: setGamePgn } = useChessActions(gameAtom);
@@ -43,26 +43,26 @@ export default function GameReport() {
<Grid <Grid
container container
item item
marginTop={{ xs: 0, md: "2.5em" }} marginTop={{ xs: 0, lg: "2.5em" }}
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
borderRadius={2} borderRadius={2}
border={1} border={1}
borderColor={"secondary.main"} borderColor={"secondary.main"}
xs={12} xs={12}
md lg
sx={{ sx={{
backgroundColor: "secondary.main", backgroundColor: "secondary.main",
borderColor: "primary.main", borderColor: "primary.main",
borderWidth: 2, borderWidth: 2,
}} }}
padding={3} padding={3}
gap={3} rowGap={3}
style={{ style={{
maxWidth: "1100px", maxWidth: "1100px",
}} }}
> >
{isMdOrGreater ? <ReviewPanelHeader /> : <ReviewPanelToolBar />} {isLgOrGreater ? <ReviewPanelHeader /> : <ReviewPanelToolBar />}
<Divider sx={{ width: "90%" }} /> <Divider sx={{ width: "90%" }} />
@@ -70,7 +70,7 @@ export default function GameReport() {
<Divider sx={{ width: "90%" }} /> <Divider sx={{ width: "90%" }} />
{isMdOrGreater ? <ReviewPanelToolBar /> : <ReviewPanelHeader />} {isLgOrGreater ? <ReviewPanelToolBar /> : <ReviewPanelHeader />}
</Grid> </Grid>
</Grid> </Grid>
); );

View File

@@ -44,7 +44,9 @@ export default function EvaluationBar({ height }: Props) {
: evalBar.whiteBarPercentage : evalBar.whiteBarPercentage
}%`} }%`}
width="100%" width="100%"
borderRadius="5px 5px 0 0" borderRadius={
evalBar.whiteBarPercentage === 100 ? "5px" : "5px 5px 0 0"
}
> >
<Typography <Typography
color={boardOrientation ? "white" : "black"} color={boardOrientation ? "white" : "black"}
@@ -68,7 +70,9 @@ export default function EvaluationBar({ height }: Props) {
width={"100%"} width={"100%"}
display="flex" display="flex"
alignItems="flex-end" alignItems="flex-end"
borderRadius="0 0 5px 5px" borderRadius={
evalBar.whiteBarPercentage === 100 ? "5px" : "0 0 5px 5px"
}
> >
<Typography <Typography
color={boardOrientation ? "black" : "white"} color={boardOrientation ? "black" : "white"}

View File

@@ -36,7 +36,7 @@ export default function ReviewPanelBody() {
xs={12} xs={12}
justifyContent="center" justifyContent="center"
alignItems="center" alignItems="center"
gap={1} rowGap={1}
> >
<Grid <Grid
item item

View File

@@ -14,17 +14,23 @@ export default function LineEvaluation({ line }: Props) {
line.cp !== undefined line.cp !== undefined
? `${line.cp / 100}` ? `${line.cp / 100}`
: line.mate : line.mate
? `Mate in ${Math.abs(line.mate)}` ? `${line.mate > 0 ? "" : "-"}M${Math.abs(line.mate)}`
: "?"; : "?";
const showSkeleton = line.depth < 6; const showSkeleton = line.depth < 6;
return ( return (
<ListItem disablePadding> <ListItem disablePadding>
<Typography marginRight={2} marginY={0.5}> <Typography
marginRight={1.5}
marginY={0.5}
noWrap
overflow="visible"
width="3em"
textAlign="center"
>
{showSkeleton ? ( {showSkeleton ? (
<Skeleton <Skeleton
width={"2em"}
variant="rounded" variant="rounded"
animation="wave" animation="wave"
sx={{ color: "transparent" }} sx={{ color: "transparent" }}
@@ -36,11 +42,14 @@ export default function LineEvaluation({ line }: Props) {
)} )}
</Typography> </Typography>
<Typography noWrap> <Typography
noWrap
maxWidth={{ xs: "15em", sm: "25em", md: "30em", lg: "25em" }}
>
{showSkeleton ? ( {showSkeleton ? (
<Skeleton width={"20em"} variant="rounded" animation="wave" /> <Skeleton variant="rounded" animation="wave" />
) : ( ) : (
line.pv.slice(0, 10).map(moveLineUciToSan(board.fen())).join(", ") line.pv.map(moveLineUciToSan(board.fen())).join(", ")
)} )}
</Typography> </Typography>
</ListItem> </ListItem>