|
1 |
| -import React from 'react' |
2 |
| -import { useGlobalContext } from './context' |
| 1 | +import React from "react"; |
| 2 | +import { useGlobalContext } from "./context"; |
3 | 3 |
|
4 | 4 | const SetupForm = () => {
|
5 |
| - return <h2>setup form</h2> |
6 |
| -} |
| 5 | + const { quiz, handleChange, handleSubmit, error } = useGlobalContext(); |
7 | 6 |
|
8 |
| -export default SetupForm |
| 7 | + return ( |
| 8 | + <main> |
| 9 | + <section className="quiz quiz-small"> |
| 10 | + <form className="setup-form"> |
| 11 | + <h2>setup quiz</h2> |
| 12 | + |
| 13 | + {/* amount */} |
| 14 | + <div className="form-control"> |
| 15 | + <label htmlFor="amount">number of questions</label> |
| 16 | + <input |
| 17 | + type="number" |
| 18 | + name="amount" |
| 19 | + id="amount" |
| 20 | + className="form-input" |
| 21 | + value={quiz.amount} |
| 22 | + onChange={handleChange} |
| 23 | + min={1} |
| 24 | + max={50} |
| 25 | + /> |
| 26 | + </div> |
| 27 | + |
| 28 | + {/* category */} |
| 29 | + <div className="form-control"> |
| 30 | + <label htmlFor="category">category</label> |
| 31 | + <select |
| 32 | + name="category" |
| 33 | + id="category" |
| 34 | + className="form-input" |
| 35 | + value={quiz.category} |
| 36 | + onChange={handleChange} |
| 37 | + > |
| 38 | + <option value="sports">sports</option> |
| 39 | + <option value="history">history</option> |
| 40 | + <option value="politics">politics</option> |
| 41 | + </select> |
| 42 | + </div> |
| 43 | + |
| 44 | + {/* difficulty */} |
| 45 | + <div className="form-control"> |
| 46 | + <label htmlFor="difficulty">select difficulty</label> |
| 47 | + <select |
| 48 | + name="difficulty" |
| 49 | + id="difficulty" |
| 50 | + className="form-input" |
| 51 | + value={quiz.difficulty} |
| 52 | + onChange={handleChange} |
| 53 | + > |
| 54 | + <option value="easy">easy</option> |
| 55 | + <option value="medium">history</option> |
| 56 | + <option value="hard">politics</option> |
| 57 | + </select> |
| 58 | + </div> |
| 59 | + {error && ( |
| 60 | + <div className="error"> |
| 61 | + can't generate questions, please try different options |
| 62 | + </div> |
| 63 | + )} |
| 64 | + <button className="submit-btn" onClick={handleSubmit}> |
| 65 | + play quiz |
| 66 | + </button> |
| 67 | + </form> |
| 68 | + </section> |
| 69 | + </main> |
| 70 | + ); |
| 71 | +}; |
| 72 | + |
| 73 | +export default SetupForm; |
0 commit comments