Skip to content

Commit

Permalink
fix: stop arrows being drawn when areArrowsAllowed set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
Clariity committed Oct 13, 2023
1 parent 1ab2ee4 commit 3107671
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/chessboard/context/chessboard-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface ChessboardProviderContext {
animationDuration: RequiredChessboardProps["animationDuration"];
arePiecesDraggable: RequiredChessboardProps["arePiecesDraggable"];
arePremovesAllowed: RequiredChessboardProps["arePremovesAllowed"];
autoPromoteToQueen: RequiredChessboardProps["autoPromoteToQueen"];
boardOrientation: RequiredChessboardProps["boardOrientation"];
boardWidth: RequiredChessboardProps["boardWidth"];
customArrowColor: RequiredChessboardProps["customArrowColor"];
Expand All @@ -70,14 +71,15 @@ interface ChessboardProviderContext {
promotionDialogVariant: RequiredChessboardProps["promotionDialogVariant"];
showBoardNotation: RequiredChessboardProps["showBoardNotation"];
snapToCursor: RequiredChessboardProps["snapToCursor"];
autoPromoteToQueen: RequiredChessboardProps["autoPromoteToQueen"];

// Exported by context
arrows: Arrow[];
chessPieces: CustomPieces | Record<string, ReactNode>;
clearArrows: () => void;
clearCurrentRightClickDown: () => void;
currentPosition: BoardPosition;
currentRightClickDown?: Square;
drawNewArrow: (from: Square, to: Square) => void;
handleSetPosition: (
sourceSq: Square,
targetSq: Square,
Expand All @@ -86,6 +88,8 @@ interface ChessboardProviderContext {
) => void;
isWaitingForAnimation: boolean;
lastPieceColour: string | undefined;
newArrow?: Arrow;
onArrowDrawEnd: (from: Square, to: Square) => void;
onRightClickDown: (square: Square) => void;
onRightClickUp: (square: Square) => void;
positionDifferences: { added: BoardPosition; removed: BoardPosition };
Expand All @@ -96,10 +100,6 @@ interface ChessboardProviderContext {
setPromoteToSquare: React.Dispatch<React.SetStateAction<Square | null>>;
setShowPromoteDialog: React.Dispatch<React.SetStateAction<boolean>>;
showPromoteDialog: boolean;
newArrow?: Arrow;
onArrowDrawEnd: (from: Square, to: Square) => void;
drawNewArrow: (from: Square, to: Square) => void;
currentRightClickDown?: Square;
}

export const ChessboardContext = createContext({} as ChessboardProviderContext);
Expand All @@ -113,6 +113,7 @@ export const ChessboardProvider = forwardRef(
areArrowsAllowed = true,
arePiecesDraggable = true,
arePremovesAllowed = false,
autoPromoteToQueen = false,
boardOrientation = "white",
boardWidth,
children,
Expand Down Expand Up @@ -162,7 +163,6 @@ export const ChessboardProvider = forwardRef(
showBoardNotation = true,
showPromotionDialog = false,
snapToCursor = true,
autoPromoteToQueen = false,
}: ChessboardProviderProps,
ref
) => {
Expand Down
2 changes: 1 addition & 1 deletion src/chessboard/hooks/useArrows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const useArrows = (
const allBoardArrows = [...arrows, ...customArrowsSet];

const onArrowDrawEnd = (fromSquare: Square, toSquare: Square) => {
if (fromSquare === toSquare) return;
if (fromSquare === toSquare || !areArrowsAllowed) return;

let arrowsCopy;
const newArrow: Arrow = [fromSquare, toSquare, customArrowColor];
Expand Down

0 comments on commit 3107671

Please sign in to comment.