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

Implementing the Give Up button #124 #125

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const difficulty = {
hard: 'hard',
}

const GIVE_UP_TIME_OUT = 40000

const getRandomAnswer = () => {
const randomIndex = Math.floor(Math.random() * answers.length)
return answers[randomIndex].toUpperCase()
Expand Down Expand Up @@ -112,6 +114,19 @@ function App() {
setInfoModalIsOpen(false)
}

const [hideGiveUp,setHideGiveUp] = useState(true)

useEffect(()=>{
setHideGiveUp(true)
const giveUpTimer = window.setTimeout(() => {
setHideGiveUp(false)
}, GIVE_UP_TIME_OUT);

return () => {
clearTimeout(giveUpTimer);
};
}, [gameState])

const [darkMode, setDarkMode] = useLocalStorage('dark-mode', false)
const toggleDarkMode = () => setDarkMode((prev: boolean) => !prev)

Expand Down Expand Up @@ -404,6 +419,22 @@ function App() {
))
)}
</div>
<div
className={`flex justify-center pt-6 ${
hideGiveUp || gameState !== state.playing ? 'hidden' : ''
}`}
>
<div className={darkMode ? 'dark' : ''}>
<button
autoFocus
type="button"
className="rounded-lg z-10 px-6 py-2 text-lg nm-flat-background dark:nm-flat-background-dark hover:nm-inset-background dark:hover:nm-inset-background-dark text-primary dark:text-primary-dark"
onClick={() => {setGameState(state.lost); setCurrentStreak(0)}}
>
Give Up
</button>
</div>
</div>
<div
className={`absolute -bottom-24 left-1/2 transform -translate-x-1/2 ${
gameState === state.playing ? 'hidden' : ''
Expand Down