-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
93 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,49 @@ | ||
import NiceModal, { useModal } from '@ebay/nice-modal-react'; | ||
import { Dialog } from '@reach/dialog'; | ||
import { weights } from './weights'; | ||
import { useState } from 'react'; | ||
|
||
const weightValues = Object.values(weights); | ||
const easyCountries = weightValues.filter((weight) => weight >= 0.8).length; | ||
const mediumCountries = weightValues.filter((weight) => weight >= 0.5).length; | ||
const hardCountries = weightValues.filter((weight) => weight >= 0.3).length; | ||
const veryHardCountries = weightValues.length; | ||
|
||
export const IntroModal = NiceModal.create(({ onStart }) => { | ||
const modal = useModal(); | ||
|
||
function startGame() { | ||
onStart(); | ||
function startGame(event) { | ||
event.preventDefault(); | ||
const data = new FormData(event.target); | ||
onStart(data.get('difficulty')); | ||
modal.hide(); | ||
} | ||
|
||
return ( | ||
<Dialog isOpen={modal.visible} onDismiss={modal.hide}> | ||
<div className="modal modal--intro"> | ||
<form className="modal modal--intro" onSubmit={startGame}> | ||
<h1>Country Guesser</h1> | ||
<h2>How to play</h2> | ||
<p>Type the name of the country highlighted.</p> | ||
<button type="button" onClick={startGame}> | ||
Start | ||
</button> | ||
</div> | ||
<h2>Select difficulty</h2> | ||
<label> | ||
<input type="radio" name="difficulty" value="easy" /> American ( | ||
{easyCountries} countries) | ||
</label> | ||
<label> | ||
<input type="radio" name="difficulty" value="medium" /> Tourist ( | ||
{mediumCountries} countries) | ||
</label> | ||
<label> | ||
<input type="radio" name="difficulty" value="hard" defaultChecked />{' '} | ||
GeoGuessr enjoyer ({hardCountries} countries) | ||
</label> | ||
<label> | ||
<input type="radio" name="difficulty" value="veryHard" /> Ultra | ||
violence ({veryHardCountries} countries) | ||
</label> | ||
<button type="submit">Start</button> | ||
</form> | ||
</Dialog> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.