fix : infinite rerenders

This commit is contained in:
GuillaumeSD
2024-02-25 03:02:59 +01:00
parent 7412f708d0
commit 2af25cf4ec
11 changed files with 50 additions and 47 deletions

View File

@@ -5,7 +5,7 @@ import { boardAtom, gameAtom } from "../states";
import { useChessActions } from "@/hooks/useChess";
export default function GoToLastPositionButton() {
const boardActions = useChessActions(boardAtom);
const { setPgn: setBoardPgn } = useChessActions(boardAtom);
const game = useAtomValue(gameAtom);
const board = useAtomValue(boardAtom);
@@ -20,7 +20,7 @@ export default function GoToLastPositionButton() {
<IconButton
onClick={() => {
if (isButtonDisabled) return;
boardActions.setPgn(game.pgn());
setBoardPgn(game.pgn());
}}
disabled={isButtonDisabled}
>

View File

@@ -10,7 +10,8 @@ import SaveButton from "./saveButton";
export default function ReviewPanelToolBar() {
const board = useAtomValue(boardAtom);
const boardActions = useChessActions(boardAtom);
const { reset: resetBoard, undoMove: undoBoardMove } =
useChessActions(boardAtom);
const boardHistory = board.history();
@@ -21,7 +22,7 @@ export default function ReviewPanelToolBar() {
<Tooltip title="Reset board">
<Grid>
<IconButton
onClick={() => boardActions.reset()}
onClick={() => resetBoard()}
disabled={boardHistory.length === 0}
>
<Icon icon="ri:skip-back-line" />
@@ -32,7 +33,7 @@ export default function ReviewPanelToolBar() {
<Tooltip title="Go to previous move">
<Grid>
<IconButton
onClick={() => boardActions.undo()}
onClick={() => undoBoardMove()}
disabled={boardHistory.length === 0}
>
<Icon icon="ri:arrow-left-s-line" height={30} />

View File

@@ -5,7 +5,7 @@ import { boardAtom, gameAtom } from "../states";
import { useChessActions } from "@/hooks/useChess";
export default function NextMoveButton() {
const boardActions = useChessActions(boardAtom);
const { makeMove: makeBoardMove } = useChessActions(boardAtom);
const game = useAtomValue(gameAtom);
const board = useAtomValue(boardAtom);
@@ -23,7 +23,7 @@ export default function NextMoveButton() {
const nextMove = game.history({ verbose: true })[nextMoveIndex];
if (nextMove) {
boardActions.move({
makeBoardMove({
from: nextMove.from,
to: nextMove.to,
promotion: nextMove.promotion,