improve moveFrom safety
This commit is contained in:
@@ -34,7 +34,7 @@ export default function GamePage({ initialLobby }: { initialLobby: Game }) {
|
|||||||
check: {}
|
check: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
const [moveFrom, setMoveFrom] = useState<string | Square>("");
|
const [moveFrom, setMoveFrom] = useState<string | Square | null>(null);
|
||||||
|
|
||||||
const [chatMessages, setChatMessages] = useState<Message[]>([]);
|
const [chatMessages, setChatMessages] = useState<Message[]>([]);
|
||||||
const [boardWidth, setBoardWidth] = useState(480);
|
const [boardWidth, setBoardWidth] = useState(480);
|
||||||
@@ -193,8 +193,6 @@ export default function GamePage({ initialLobby }: { initialLobby: Game }) {
|
|||||||
updateCustomSquares({
|
updateCustomSquares({
|
||||||
options: {}
|
options: {}
|
||||||
});
|
});
|
||||||
console.log(m);
|
|
||||||
console.log(err);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -268,7 +266,7 @@ export default function GamePage({ initialLobby }: { initialLobby: Game }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// from square
|
// from square
|
||||||
if (!moveFrom) {
|
if (moveFrom === null) {
|
||||||
resetFirstMove(square);
|
resetFirstMove(square);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -283,7 +281,7 @@ export default function GamePage({ initialLobby }: { initialLobby: Game }) {
|
|||||||
if (!move) {
|
if (!move) {
|
||||||
resetFirstMove(square);
|
resetFirstMove(square);
|
||||||
} else {
|
} else {
|
||||||
setMoveFrom("");
|
setMoveFrom(null);
|
||||||
socket.emit("sendMove", moveDetails);
|
socket.emit("sendMove", moveDetails);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user