Skip to content

Commit 4521aa5

Browse files
committed
add change question functionality
1 parent 494aa74 commit 4521aa5

14 files changed

+2236
-134
lines changed

content/en.json

Lines changed: 1850 additions & 0 deletions
Large diffs are not rendered by default.

content/supportedLanguages.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
[
3+
"en",
4+
"English"
5+
],
6+
[
7+
"es",
8+
"Español (Spanish) "
9+
],
10+
[
11+
"fr",
12+
"Français (French) "
13+
],
14+
[
15+
"de",
16+
"Deutsch (German)"
17+
],
18+
[
19+
"id",
20+
"Indonesia (Indonesian)"
21+
],
22+
[
23+
"ru",
24+
"Русский (Russian)"
25+
],
26+
[
27+
"zh-cn",
28+
"简体中文 (Mainland Chinese)"
29+
],
30+
[
31+
"pt-br",
32+
"Português Brasil (Brazilian Portuguese)"
33+
],
34+
[
35+
"ja",
36+
"日本語 (Japanese)"
37+
],
38+
[
39+
"ko",
40+
"한국어 (Korean)"
41+
]
42+
]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"prop-types": "^15.7.2",
2424
"react": "latest",
2525
"react-dom": "latest",
26+
"react-icons": "^3.10.0",
2627
"react-markdown": "^4.3.1",
2728
"react-syntax-highlighter": "^13.2.1",
2829
"rebass": "^4.0.7",

src/components/Context.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
const AppContext = React.createContext();
4+
5+
export default AppContext;

src/components/Game.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import React, { useState, useContext } from "react";
2+
import Question from './Question';
3+
import GameNavigation from './GameNavigation';
4+
import LanguageQuestionsCompleted from './LanguageQuestionsCompleted';
25

36
export default function GameWithContext() {
4-
return <p>derp derp derp</p>;
7+
return(<>
8+
<GameNavigation/>
9+
<Question/>
10+
<LanguageQuestionsCompleted/>
11+
</>);
512
}

src/components/GameNavigation.js

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,108 @@
11
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+
};
255

356
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+
);
5108
}

src/components/GameWithContext.js

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,53 @@
1-
//notes on game:
2-
/*
3-
so the game will basically be a full client-side react app with state management and data persistence occurring in the browser
4-
5-
so at this top "app" lvl, need to set context, and then there are basically 2 parallel systems running to persist data, context that the app is doing, and then a mirror image of it is being passed to localstorage for when the user comes back to the website.
6-
7-
*/
8-
import React, {useState, useContext} from 'react';
1+
import React, {useState, useEffect, useContext} from 'react';
2+
import Context from './Context';
3+
import Game from './Game'
4+
import setUpGameState from '../state-management/setUpGameState';
95

106
export default function GameWithContext(){
7+
const [activeQuestionNum, setActiveQuestion] = useState({});
8+
const [language, setLanguage] = useState("");
9+
const [questions, setQuestions] = useState([]);
10+
const [questionsCompleted, setQuestionsCompleted] = useState([]);
11+
12+
useEffect(()=>{
13+
(async()=>{
14+
const state = await setUpGameState();
15+
const {activeLanguage, activeLangQuestions, activeLangAnswered, activeQuestionNum} = state;
16+
setActiveQuestion(activeQuestionNum);
17+
setLanguage(activeLanguage);
18+
setQuestions(activeLangQuestions);
19+
setQuestionsCompleted(activeLangAnswered);
20+
})();
21+
},[]);
1122

12-
return(<p>
13-
derp derp derp
14-
</p>)
23+
const restartGame = (lang)=>{
24+
return
25+
}
26+
const goToPrevQuestion = () => {
27+
if(activeQuestionNum > 1) setActiveQuestion(activeQuestionNum - 1);
28+
};
29+
const goToNextQuestion = () => {
30+
if (activeQuestionNum < questions.length) setActiveQuestion(activeQuestionNum + 1);
31+
};
32+
const goToRandomUnvisitedQuestion = () => {
33+
return;
34+
};
35+
const updateQuestionsCompleted = (question, answer) => {
36+
return;
37+
}
38+
const context = {
39+
goToNextQuestion,
40+
goToPrevQuestion,
41+
goToRandomUnvisitedQuestion,
42+
restartGame,
43+
activeQuestionNum,
44+
language,
45+
questions,
46+
questionsCompleted,
47+
};
48+
return(
49+
<Context.Provider value={context}>
50+
<Game />
51+
</Context.Provider>
52+
)
1553
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, { useState, useContext } from "react";
2+
import { Box, Button, Text } from "rebass";
3+
4+
export default function LanguageQuestionsCompleted() {
5+
return (
6+
<nav>
7+
<div>
8+
</div>
9+
<div></div>
10+
</nav>
11+
);
12+
}

0 commit comments

Comments
 (0)