Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base the disable of the accept score button on the state of accepted #2832

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/views/Game/PlayControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,12 @@ export function PlayControls({
const [white_accepted, set_white_accepted] = React.useState(
stoneRemovalAccepted(goban, "white"),
);
const [stone_removal_string, set_stone_removal_string] = React.useState(
goban.engine.getStoneRemovalString(),
);

// Setup: when there's a new goban in play, we need to make sure we have the current
// state of acceptance captured
React.useEffect(() => {
const syncStoneRemovalAcceptance = () => {
if (goban.engine.phase === "stone removal") {
set_stone_removal_string(goban.engine.getStoneRemovalString());
set_black_accepted(stoneRemovalAccepted(goban, "black"));
set_white_accepted(stoneRemovalAccepted(goban, "white"));
}
Expand All @@ -176,6 +175,7 @@ export function PlayControls({
syncStoneRemovalAcceptance,
);
}, [goban]);

React.useEffect(() => {
const syncNeedsSealing = (locs?: JGOFSealingIntersection[]) => {
setNeedsSealing(locs);
Expand Down Expand Up @@ -222,12 +222,25 @@ export function PlayControls({
goban.off("stone-removal.auto-scoring-complete", onAutoScoringComplete);
};
}, [goban]);

/*
React.useEffect(() => {
setStoneRemovalAcceptDisabled(true);
const timeout = setTimeout(() => setStoneRemovalAcceptDisabled(false), 1500);
const timeout = setTimeout(() => {
console.log("setting false");
setStoneRemovalAcceptDisabled(false);
}, 1500);

return () => clearTimeout(timeout);
}, [stone_removal_string]);
*/

React.useEffect(() => {
const player_accepted =
goban.engine?.playerColor(user.id) === "black" ? black_accepted : white_accepted;

setStoneRemovalAcceptDisabled(player_accepted ?? false);
}, [black_accepted, white_accepted]);

const paused = usePaused(goban);
const show_undo_requested = useShowUndoRequested(goban);
Expand Down Expand Up @@ -302,13 +315,11 @@ export function PlayControls({
});
return false;
};
const onStoneRemovalAccept = () => {
const onStoneRemovalAccept = (): void => {
goban.acceptRemovedStones();
return false;
};
const onStoneRemovalAutoScore = () => {
const onStoneRemovalAutoScore = (): void => {
goban.performStoneRemovalAutoScoring();
return false;
};

const sse = engine.stalling_score_estimate;
Expand Down
Loading