style : engine settings dialog

This commit is contained in:
GuillaumeSD
2024-02-25 18:34:11 +01:00
parent 2b90fbb967
commit ebdfc9ae33
10 changed files with 172 additions and 66 deletions

View File

@@ -72,7 +72,7 @@ export default function ReviewPanelBody() {
)}
<Grid item container xs={12} justifyContent="center" alignItems="center">
<List>
<List sx={{ maxWidth: "95%" }}>
{engineLines.map((line) => (
<LineEvaluation key={line.multiPv} line={line} />
))}

View File

@@ -36,7 +36,7 @@ export default function LineEvaluation({ line }: Props) {
)}
</Typography>
<Typography>
<Typography noWrap>
{showSkeleton ? (
<Skeleton width={"20em"} variant="rounded" animation="wave" />
) : (

View File

@@ -1,22 +1,20 @@
import { Icon } from "@iconify/react";
import { Grid } from "@mui/material";
import { useState } from "react";
import {
engineDepthAtom,
engineMultiPvAtom,
gameAtom,
gameEvalAtom,
} from "./states";
} from "../states";
import { useAtomValue, useSetAtom } from "jotai";
import { getFens } from "@/lib/chess";
import { useGameDatabase } from "@/hooks/useGameDatabase";
import { LoadingButton } from "@mui/lab";
import Slider from "@/components/slider";
import { useEngine } from "@/hooks/useEngine";
import { EngineName } from "@/types/enums";
import { logAnalyticsEvent } from "@/lib/firebase";
export default function AnalyzePanel() {
export default function AnalyzeButton() {
const engine = useEngine(EngineName.Stockfish16);
const [evaluationInProgress, setEvaluationInProgress] = useState(false);
const engineDepth = useAtomValue(engineDepthAtom);
@@ -58,52 +56,25 @@ export default function AnalyzePanel() {
};
return (
<Grid
item
container
xs={12}
justifyContent="center"
alignItems="center"
rowGap={3}
<LoadingButton
variant="contained"
size="large"
startIcon={
!evaluationInProgress && (
<Icon icon="streamline:magnifying-glass-solid" />
)
}
onClick={handleAnalyze}
disabled={!readyToAnalyse}
loading={evaluationInProgress}
loadingPosition={evaluationInProgress ? "end" : undefined}
endIcon={
evaluationInProgress && (
<Icon icon="streamline:magnifying-glass-solid" />
)
}
>
<Slider
label="Maximum depth"
atom={engineDepthAtom}
min={10}
max={30}
marksFilter={2}
/>
<Slider
label="Number of lines"
atom={engineMultiPvAtom}
min={1}
max={6}
xs={6}
/>
<Grid item container xs={12} justifyContent="center" alignItems="center">
<LoadingButton
variant="contained"
size="large"
startIcon={
!evaluationInProgress && (
<Icon icon="streamline:magnifying-glass-solid" />
)
}
onClick={handleAnalyze}
disabled={!readyToAnalyse}
loading={evaluationInProgress}
loadingPosition={evaluationInProgress ? "end" : undefined}
endIcon={
evaluationInProgress && (
<Icon icon="streamline:magnifying-glass-solid" />
)
}
>
{evaluationInProgress ? "Analyzing..." : "Analyze"}
</LoadingButton>
</Grid>
</Grid>
{evaluationInProgress ? "Analyzing..." : "Analyze"}
</LoadingButton>
);
}

View File

@@ -2,6 +2,8 @@ import { Icon } from "@iconify/react";
import { Grid, Typography } from "@mui/material";
import GamePanel from "./gamePanel";
import LoadGame from "./loadGame";
import AnalyzeButton from "./analyzeButton";
import EngineSettingsButton from "@/sections/engineSettings/engineSettingsButton";
export default function ReviewPanelHeader() {
return (
@@ -37,6 +39,8 @@ export default function ReviewPanelHeader() {
>
<GamePanel />
<LoadGame />
<AnalyzeButton />
<EngineSettingsButton />
</Grid>
</Grid>
);

View File

@@ -1,13 +1,11 @@
import { Checkbox, FormControlLabel, Grid } from "@mui/material";
import { useAtom, useAtomValue } from "jotai";
import { useAtom } from "jotai";
import {
gameEvalAtom,
showBestMoveArrowAtom,
showPlayerMoveArrowAtom,
} from "./states";
} from "../analysis/states";
export default function ArrowOptions() {
const gameEval = useAtomValue(gameEvalAtom);
const [showBestMove, setShowBestMove] = useAtom(showBestMoveArrowAtom);
const [showPlayerMove, setShowPlayerMove] = useAtom(showPlayerMoveArrowAtom);
@@ -25,7 +23,6 @@ export default function ArrowOptions() {
<Checkbox
checked={showBestMove}
onChange={(_, checked) => setShowBestMove(checked)}
disabled={!gameEval}
/>
}
label="Show best move green arrow"

View File

@@ -0,0 +1,20 @@
import { Button } from "@mui/material";
import { useState } from "react";
import EngineSettingsDialog from "./engineSettingsDialog";
export default function EngineSettingsButton() {
const [openDialog, setOpenDialog] = useState(false);
return (
<>
<Button variant="contained" onClick={() => setOpenDialog(true)}>
Engine Settings
</Button>
<EngineSettingsDialog
open={openDialog}
onClose={() => setOpenDialog(false)}
/>
</>
);
}

View File

@@ -0,0 +1,95 @@
import Slider from "@/components/slider";
import { EngineName } from "@/types/enums";
import {
MenuItem,
Select,
Button,
Dialog,
DialogTitle,
DialogContent,
FormControl,
InputLabel,
OutlinedInput,
DialogActions,
Typography,
Grid,
} from "@mui/material";
import { engineDepthAtom, engineMultiPvAtom } from "../analysis/states";
import ArrowOptions from "./arrowOptions";
interface Props {
open: boolean;
onClose: () => void;
}
export default function EngineSettingsDialog({ open, onClose }: Props) {
return (
<Dialog open={open} onClose={onClose} maxWidth="md" fullWidth>
<DialogTitle marginY={1} variant="h5">
Set engine parameters
</DialogTitle>
<DialogContent>
<Typography>
Only Stockfish 16 is available now, more engine choices will come !
</Typography>
<Grid
marginTop={4}
item
container
justifyContent="center"
alignItems="center"
xs={12}
rowGap={3}
>
<Grid item container xs={12} justifyContent="center">
<FormControl variant="outlined">
<InputLabel id="dialog-select-label">Engine</InputLabel>
<Select
labelId="dialog-select-label"
id="dialog-select"
displayEmpty
input={<OutlinedInput label="Engine" />}
value={EngineName.Stockfish16}
disabled={true}
sx={{ width: 200 }}
>
{Object.values(EngineName).map((engine) => (
<MenuItem key={engine} value={engine}>
{engineLabel[engine]}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
<Slider
label="Maximum depth"
atom={engineDepthAtom}
min={10}
max={30}
marksFilter={2}
/>
<Slider
label="Number of lines"
atom={engineMultiPvAtom}
min={1}
max={6}
xs={6}
/>
<ArrowOptions />
</Grid>
</DialogContent>
<DialogActions sx={{ m: 2 }}>
<Button variant="contained" onClick={onClose}>
Done
</Button>
</DialogActions>
</Dialog>
);
}
const engineLabel: Record<EngineName, string> = {
[EngineName.Stockfish16]: "Stockfish 16",
};