learn-morse-code/src/components/ChallengeOverlay.js

43 lines
1.6 KiB
JavaScript
Raw Normal View History

import React, { useContext, useEffect } from "react"
import { GameClockContext } from "../contexts/gameClockContext"
import WordListPicker from "./WordListPicker"
// import { GameModeContext } from "../contexts/gameModeContext"
export default (function ChallengeOverlay() {
const {startGameClock} = useContext(GameClockContext)
// const {gameMode} = useContext(GameModeContext)
function startChallenge(e) {
let countdown
let count = 3
document.getElementById('challengeReady').classList.add('starting')
document.getElementById('challengeReady').innerHTML = `<span id="message">Challenge starting in</span><span id="count">${count}</span>`
countdown = setInterval(() => {
count--
if (count === 0) {
// Do this when countdown hits 0
2020-02-05 02:45:42 +01:00
document.getElementById('challenge-overlay').classList.add('fade')
clearInterval(countdown)
2020-02-05 02:45:42 +01:00
setTimeout(() => {
document.getElementById('challenge-overlay').classList.add('hide')
startGameClock()
}, 900);
}
document.getElementById('challengeReady').innerHTML = `<span id="message">Challenge starting in</span><span id="count">${count}</span>`
}, 1000)
}
return (
<div id="challenge-overlay">
<div id="challengeReady" className="notify">
2020-02-05 02:45:42 +01:00
<h2>Challenge Options</h2>
<WordListPicker />
2020-02-05 02:45:42 +01:00
<button id="startChallenge" onClick={startChallenge}>Start Challenge</button>
</div>
</div>
)
})