Skip to content

Commit 266817a

Browse files
committed
fix(guess-the-word): disable random button when showing correct word
1 parent 124a4c9 commit 266817a

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

vanilla/guess-the-word/src/events/handlers/game-over.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { setIsAlertInitialized } from "@/state/alert";
22
import { showCorrectWord } from "@/ui/word";
33
import { $hints, $hintsContent } from "@/ui/hints/elements";
4-
import { $reset } from "@/ui/actions";
4+
import { $randomWord, $reset } from "@/ui/actions";
55
import { CLASSES } from "@/consts/css-classes";
66

77
/** @param {Object} params
@@ -12,7 +12,8 @@ export function handleGameOver({ $currentField }) {
1212
GameAlert.show({ color: "error", text: "😔 Game Over!" });
1313
});
1414

15-
showCorrectWord();
15+
$randomWord.disabled = true;
16+
showCorrectWord().then(() => ($randomWord.disabled = false));
1617

1718
$hints.classList.add(CLASSES.HIDDEN);
1819
$hintsContent.classList.add(CLASSES.HIDDEN);

vanilla/guess-the-word/src/events/handlers/game-success.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { hasCompletedAllDifficulties } from "@/utils/difficulty/completed";
77
import { InsaneDifficulty } from "@/utils/difficulty/insane";
88
import { showCorrectWord } from "@/ui/word";
99
import { $hints, $hintsContent } from "@/ui/hints/elements";
10-
import { $reset } from "@/ui/actions";
10+
import { $randomWord, $reset } from "@/ui/actions";
1111
import { CLASSES } from "@/consts/css-classes";
1212

1313
export function handleGameSuccess() {
@@ -16,7 +16,8 @@ export function handleGameSuccess() {
1616
GameAlert.show({ color: "success", text: "🎉 Success!" });
1717
});
1818

19-
showCorrectWord();
19+
$randomWord.disabled = true;
20+
showCorrectWord().then(() => ($randomWord.disabled = false));
2021

2122
if (InsaneDifficulty.isApplied())
2223
import("@/ui/insane-countdown-bar").then(({ InsaneCountdownBar }) =>

vanilla/guess-the-word/src/events/handlers/random-word.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { RESETS } from "@/consts/resets";
1919
import { CLASSES } from "@/consts/css-classes";
2020

2121
export async function generateRandomWord() {
22-
// FIX: disable random button while showing correct word
22+
// TODO: add auxiliary state to ensure that the button is disabled even if
23+
// manipulating the DOM
2324

2425
if (words.length === 0) {
2526
import("./difficulty-complete").then(({ handleDifficultyComplete }) =>

0 commit comments

Comments
 (0)