import { useDispatch } from "react-redux" ; import { BoardState } from "@shoki/board" ; import { PlayerActions } from "@creature-chess/gamemode" ; import { PieceModel , PlayerPieceLocation } from "@creature-chess/models" ; import { GameBoardLocation } from "@creature-chess/ui" ; import { clearSelectedPiece } from "../../ui" ; import { getLocationForPiece } from "../getLocationForPiece" ; export const useOnDropPiece = ( board , bench ) => { const dispatch = useDispatch ( ) ; return ( { id , location } ) => { if ( ! board ) { return ; } const from = getLocationForPiece ( id , board , bench ) ; if ( ! from ) { return ; } const loc = { type : location . locationType , location : { x : location . x , y : ( location as any ) . y || 0 } } ; dispatch ( PlayerActions . dropPiecePlayerAction ( { pieceId : id , from , to : loc } ) ) ; dispatch ( clearSelectedPiece ( ) ) ; } ; } ;