2020-02-04 22:38:22 +01:00
|
|
|
import React, { useContext, useEffect } from "react"
|
2020-02-04 04:12:50 +01:00
|
|
|
import { GameClockContext } from "../contexts/gameClockContext"
|
2020-02-04 10:27:10 +01:00
|
|
|
import WordListPicker from "./WordListPicker"
|
2020-02-04 22:38:22 +01:00
|
|
|
// import { GameModeContext } from "../contexts/gameModeContext"
|
2020-02-04 04:12:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
export default (function ChallengeOverlay() {
|
|
|
|
|
|
|
|
|
|
const {startGameClock} = useContext(GameClockContext)
|
2020-02-04 22:38:22 +01:00
|
|
|
// const {gameMode} = useContext(GameModeContext)
|
|
|
|
|
|
2020-02-04 04:12:50 +01:00
|
|
|
|
|
|
|
|
function startChallenge(e) {
|
|
|
|
|
let countdown
|
|
|
|
|
let count = 3
|
2020-02-04 22:38:22 +01:00
|
|
|
document.getElementById('challengeReady').classList.add('starting')
|
|
|
|
|
document.getElementById('challengeReady').innerHTML = `<span id="message">Challenge starting in</span><span id="count">${count}</span>`
|
2020-02-04 04:12:50 +01:00
|
|
|
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')
|
2020-02-04 04:12:50 +01:00
|
|
|
clearInterval(countdown)
|
2020-02-05 02:45:42 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
|
document.getElementById('challenge-overlay').classList.add('hide')
|
|
|
|
|
startGameClock()
|
|
|
|
|
}, 900);
|
2020-02-04 04:12:50 +01:00
|
|
|
}
|
2020-02-04 22:38:22 +01:00
|
|
|
document.getElementById('challengeReady').innerHTML = `<span id="message">Challenge starting in</span><span id="count">${count}</span>`
|
2020-02-04 04:12:50 +01:00
|
|
|
}, 1000)
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 22:38:22 +01:00
|
|
|
|
2020-02-04 04:12:50 +01:00
|
|
|
return (
|
|
|
|
|
<div id="challenge-overlay">
|
2020-02-04 10:27:10 +01:00
|
|
|
<div id="challengeReady" className="notify">
|
2020-02-05 02:45:42 +01:00
|
|
|
<h2>Challenge Options</h2>
|
2020-02-04 10:27:10 +01:00
|
|
|
<WordListPicker />
|
2020-02-05 02:45:42 +01:00
|
|
|
<button id="startChallenge" onClick={startChallenge}>Start Challenge</button>
|
2020-02-04 10:27:10 +01:00
|
|
|
</div>
|
2020-02-04 04:12:50 +01:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})
|