|
1 | | -import { FC } from "react"; |
| 1 | +import { ChangeEventHandler, FC } from "react"; |
2 | 2 | import Modal from "../Modal"; |
3 | 3 | import Button from "../Button"; |
| 4 | +import { REGIONS } from "../../constants"; |
| 5 | +import { useAppContext } from "../../context/useAppContext"; |
4 | 6 |
|
5 | 7 | interface SelectContinentDialogProps { |
6 | 8 | close: () => void; |
7 | 9 | isOpen: boolean; |
8 | 10 | startGame: () => void; |
9 | 11 | } |
10 | 12 |
|
11 | | -const continents = [ |
12 | | - { name: "Ohio, NA", value: "us-east-2" }, |
13 | | - { name: "Oregon, NA", value: "us-west-2" }, |
14 | | - { name: "Frankfurt, Europe", value: "eu-central-1" }, |
15 | | - { name: "Cape Town, Africa", value: "af-south-1" }, |
16 | | - { name: "Melbourne, Australia", value: "ap-southeast-4" }, |
17 | | - { name: "Seoul, Asia", value: "ap-northeast-2" }, |
18 | | - { name: "Sao Paulo, SA", value: "sa-east-1" }, |
19 | | -]; |
20 | | - |
21 | 13 | const SelectContinentDialog: FC<SelectContinentDialogProps> = ({ |
22 | 14 | close, |
23 | 15 | isOpen, |
24 | 16 | startGame, |
25 | 17 | }) => { |
| 18 | + const { region, setRegion } = useAppContext(); |
| 19 | + |
| 20 | + const handleChange: ChangeEventHandler<HTMLInputElement> = (event) => { |
| 21 | + setRegion(REGIONS.find((r) => r.value === event.target.value)!); |
| 22 | + }; |
| 23 | + |
26 | 24 | return ( |
27 | 25 | <Modal isOpen={isOpen} close={close}> |
28 | 26 | <h1 className="text-5xl mb-20 text-center">Select your continent</h1> |
29 | 27 | <form> |
30 | 28 | <ul className="grid grid-cols-2 gap-y-8 text-3xl gap-x-40 mb-20"> |
31 | | - {continents.map((continent) => ( |
| 29 | + {REGIONS.map((continent) => ( |
32 | 30 | <li key={continent.value}> |
33 | | - <label className="flex gap-4 items-center"> |
| 31 | + <label className="flex gap-4 items-center cursor-pointer"> |
34 | 32 | <input |
35 | | - className="h-6 w-6" |
| 33 | + className="h-6 w-6 cursor-pointer" |
36 | 34 | name="continent" |
37 | 35 | type="radio" |
38 | 36 | value={continent.value} |
| 37 | + checked={continent.value === region.value} |
| 38 | + onChange={handleChange} |
39 | 39 | /> |
40 | 40 | {continent.name} |
41 | 41 | </label> |
|
0 commit comments