|
1 | 1 | import React, { useState, useContext } from "react";
|
| 2 | +import context from './Context'; |
| 3 | +import { Box, Button, Text } from "rebass"; |
| 4 | +import { Label, Select } from "@rebass/forms"; |
| 5 | +import supportedLangs from '../../content/supportedLanguages.json'; |
| 6 | +import {GrLanguage} from 'react-icons/gr'; |
| 7 | +import {FaArrowCircleLeft} from 'react-icons/fa'; |
| 8 | +import {FaArrowCircleRight} from 'react-icons/fa'; |
| 9 | +import {FaRandom} from 'react-icons/fa'; |
| 10 | +const styles = { |
| 11 | + navContainer: { |
| 12 | + backgroundColor: "#F5F5FA", |
| 13 | + borderRadius: ".5em", |
| 14 | + margin: "1em", |
| 15 | + padding: "1em", |
| 16 | + display: "flex", |
| 17 | + flexDirection: "row", |
| 18 | + justifyContent: "space-between", |
| 19 | + "@media screen and (max-width: 600px)": { |
| 20 | + flexDirection: "column-reverse", |
| 21 | + alignItems: 'center', |
| 22 | + }, |
| 23 | + }, |
| 24 | + navButton: { |
| 25 | + margin: ".5em", |
| 26 | + fontWeight: "bold", |
| 27 | + display: "inline-flex", |
| 28 | + alignItems: "center", |
| 29 | + "@media screen and (max-width: 600px)": { |
| 30 | + width: 50, |
| 31 | + height: 50, |
| 32 | + fontSize: 30, |
| 33 | + justifyContent: 'center', |
| 34 | + margin: '1em .25em .5em', |
| 35 | + }, |
| 36 | + '&:disabled': { |
| 37 | + cursor: 'not-allowed', |
| 38 | + opacity: 0.4 |
| 39 | + } |
| 40 | + }, |
| 41 | + langSelect: { |
| 42 | + maxWidth: 150, |
| 43 | + display: "flex", |
| 44 | + flexDirection: "row", |
| 45 | + alignItems: "center", |
| 46 | + }, |
| 47 | + label: { |
| 48 | + display: "flex", |
| 49 | + justifyContent: "flex-end", |
| 50 | + paddingRight: ".5em", |
| 51 | + fontWeight: "bold", |
| 52 | + fontSize: 25, |
| 53 | + }, |
| 54 | +}; |
2 | 55 |
|
3 | 56 | export default function GameWithContext() {
|
4 |
| - return <p>derp derp derp</p>; |
| 57 | + const { |
| 58 | + goToNextQuestion, |
| 59 | + goToPrevQuestion, |
| 60 | + goToRandomUnvisitedQuestion, |
| 61 | + activeQuestionNum, |
| 62 | + questions, |
| 63 | + } = useContext(context); |
| 64 | + |
| 65 | + const nextQuestion = () => { |
| 66 | + goToNextQuestion(); |
| 67 | + } |
| 68 | + const prevQuestion = () => { |
| 69 | + goToPrevQuestion(); |
| 70 | + }; |
| 71 | + const randomQuestion = () => { |
| 72 | + goToRandomUnvisitedQuestion() |
| 73 | + } |
| 74 | + return ( |
| 75 | + <Box sx={styles.navContainer} as="nav"> |
| 76 | + <Box> |
| 77 | + <Button |
| 78 | + sx={styles.navButton} |
| 79 | + onClick={prevQuestion} |
| 80 | + disabled={activeQuestionNum === 1} |
| 81 | + > |
| 82 | + <FaArrowCircleLeft /> |
| 83 | + </Button> |
| 84 | + <Button |
| 85 | + sx={styles.navButton} |
| 86 | + onClick={nextQuestion} |
| 87 | + disabled={activeQuestionNum === questions.length} |
| 88 | + > |
| 89 | + <FaArrowCircleRight /> |
| 90 | + </Button> |
| 91 | + <Button sx={styles.navButton} onClick={randomQuestion}> |
| 92 | + <FaRandom /> |
| 93 | + </Button> |
| 94 | + </Box> |
| 95 | + <Box sx={styles.langSelect}> |
| 96 | + <Label htmlFor="lang" sx={styles.label}> |
| 97 | + <GrLanguage /> |
| 98 | + </Label> |
| 99 | + <Select id="lang" name="lang" defaultValue="English"> |
| 100 | + {Object.entries(supportedLangs).map((langWithData) => { |
| 101 | + const lang = langWithData[1]; |
| 102 | + return <option key={lang[0]}>{lang[1]}</option>; |
| 103 | + })} |
| 104 | + </Select> |
| 105 | + </Box> |
| 106 | + </Box> |
| 107 | + ); |
5 | 108 | }
|
0 commit comments