Merge pull request #32 from alDuncanson/feature/quiz-game
feature/quiz-game
This commit is contained in:
commit
b02e9d26a6
|
@ -10,6 +10,7 @@
|
|||
"google-maps-react": "^2.0.2",
|
||||
"react": "^16.5.1",
|
||||
"react-dom": "^16.5.1",
|
||||
"react-quiz-component": "0.2.0",
|
||||
"react-router": "^4.3.1",
|
||||
"react-router-dom": "^4.3.1",
|
||||
"react-scripts": "1.1.5"
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 608 KiB |
Binary file not shown.
After Width: | Height: | Size: 152 KiB |
Binary file not shown.
After Width: | Height: | Size: 252 KiB |
Binary file not shown.
After Width: | Height: | Size: 434 KiB |
Binary file not shown.
After Width: | Height: | Size: 782 KiB |
|
@ -7,7 +7,7 @@ import Tab from '@material-ui/core/Tab';
|
|||
import Typography from '@material-ui/core/Typography';
|
||||
import Home from '../pages/Home';
|
||||
import ViewMap from '../pages/ViewMap';
|
||||
import Quiz from '../pages/Quiz';
|
||||
import QuizPage from '../pages/QuizPage';
|
||||
import SightingList from '../pages/SightingList';
|
||||
import Report from '../pages/Report';
|
||||
import Info from '../pages/Info';
|
||||
|
@ -49,19 +49,19 @@ class SimpleTabs extends React.Component {
|
|||
<AppBar position="static">
|
||||
<Tabs value={value} onChange={this.handleChange} centered>
|
||||
<Tab label="Home" />
|
||||
<Tab label="Report a Sighting"/>
|
||||
<Tab label="Report a Sighting" />
|
||||
<Tab label="Sightings" />
|
||||
<Tab label="Trail-Cam Quiz" />
|
||||
<Tab label="View Map" />
|
||||
<Tab label="Marten Info" />
|
||||
</Tabs>
|
||||
</AppBar>
|
||||
{value === 0 && <Home/>}
|
||||
{value === 1 && <Report/>}
|
||||
{value === 2 && <SightingList/>}
|
||||
{value === 3 && <Quiz/>}
|
||||
{value === 4 && <ViewMap/>}
|
||||
{value === 5 && <Info/>}
|
||||
{value === 0 && <Home />}
|
||||
{value === 1 && <Report />}
|
||||
{value === 2 && <SightingList />}
|
||||
{value === 3 && <QuizPage />}
|
||||
{value === 4 && <ViewMap />}
|
||||
{value === 5 && <Info />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,157 @@
|
|||
import React, { Fragment } from 'react';
|
||||
import Grid from '@material-ui/core/Grid';
|
||||
import PropTypes from 'prop-types';
|
||||
import { withStyles } from '@material-ui/core/styles';
|
||||
import Typography from '@material-ui/core/Typography';
|
||||
import AppBar from '@material-ui/core/AppBar';
|
||||
import Tabs from '@material-ui/core/Tabs';
|
||||
import Tab from '@material-ui/core/Tab';
|
||||
import Quiz from 'react-quiz-component';
|
||||
|
||||
/**
|
||||
* Shuffles a given array.
|
||||
* @param {*} array The array passed in.
|
||||
*/
|
||||
function shuffleArray(array) {
|
||||
var j, x, i;
|
||||
for (i = array.length - 1; i > 0; i--) {
|
||||
j = Math.floor(Math.random() * (i + 1));
|
||||
x = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = x;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
function TabContainer(props) {
|
||||
return (
|
||||
<Typography component="div" variant='headline' align='center' style={{ padding: 8 }}>
|
||||
{props.children}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
||||
TabContainer.propTypes = {
|
||||
children: PropTypes.node.isRequired,
|
||||
};
|
||||
|
||||
// Style for the tabs.
|
||||
const styles = theme => ({
|
||||
root: {
|
||||
flexGrow: 1,
|
||||
backgroundColor: theme.palette.background.paper,
|
||||
},
|
||||
});
|
||||
|
||||
class QuizGame extends React.Component {
|
||||
// The state of the component.
|
||||
state = {
|
||||
value: 0,
|
||||
};
|
||||
|
||||
// Handles tab changes.
|
||||
handleChange = (event, value) => {
|
||||
this.setState({ value });
|
||||
};
|
||||
|
||||
// Object that contains the easy quiz material.
|
||||
easyQuiz = {
|
||||
"quizTitle": "Trail Cam Quiz: Easy",
|
||||
"questions": shuffleArray([
|
||||
{
|
||||
"question": <Fragment>What animal is this?<br /><br /><img src="/quizimages/question1.jpg" alt=""></img></Fragment>,
|
||||
"questionType": "text",
|
||||
"answers": [
|
||||
"Black bear",
|
||||
"Common wombat",
|
||||
"Raccoon",
|
||||
"White-tailed deer"
|
||||
],
|
||||
"correctAnswer": "1"
|
||||
},
|
||||
{
|
||||
"question": <Fragment>What animal is this?<br /><br /><img src="/quizimages/question2.jpg" alt=""></img></Fragment>,
|
||||
"questionType": "text",
|
||||
"answers": [
|
||||
"American beaver",
|
||||
"Muskrat",
|
||||
"Porcupine",
|
||||
"Woodchuck"
|
||||
],
|
||||
"correctAnswer": "3"
|
||||
},
|
||||
{
|
||||
"question": <Fragment>What animal is this?<br /><br /><img src="/quizimages/question3.jpg" alt=""></img></Fragment>,
|
||||
"questionType": "text",
|
||||
"answers": [
|
||||
"American badger",
|
||||
"Raccoon",
|
||||
"Striped skunk",
|
||||
"Virginia opossum"
|
||||
],
|
||||
"correctAnswer": "2"
|
||||
},
|
||||
{
|
||||
"question": <Fragment>What animal is this?<br /><br /><img src="/quizimages/question4.jpg" alt=""></img></Fragment>,
|
||||
"questionType": "text",
|
||||
"answers": [
|
||||
"Eastern fox squirrel",
|
||||
"Eastern gray squirrel",
|
||||
"Red squirrel",
|
||||
"Southern flying squirrel"
|
||||
],
|
||||
"correctAnswer": "3"
|
||||
},
|
||||
{
|
||||
"question": <Fragment>What animal is this?<br /><br /><img src="/quizimages/question5.jpg" alt=""></img></Fragment>,
|
||||
"questionType": "text",
|
||||
"answers": [
|
||||
"American Crow",
|
||||
"Black Vulture",
|
||||
"Turkey Vulture",
|
||||
"Northern Raven"
|
||||
],
|
||||
"correctAnswer": "3"
|
||||
},
|
||||
])
|
||||
};
|
||||
|
||||
// Renders the quiz component.
|
||||
render() {
|
||||
const { classes } = this.props;
|
||||
const { value } = this.state;
|
||||
|
||||
return (
|
||||
// Tabs
|
||||
<div className={classes.root}>
|
||||
<AppBar position="static">
|
||||
<Tabs
|
||||
value={value}
|
||||
centered
|
||||
fullWidth
|
||||
onChange={this.handleChange}
|
||||
>
|
||||
<Tab label="Easy" />
|
||||
<Tab label="Medium" />
|
||||
<Tab label="Hard" />
|
||||
</Tabs>
|
||||
</AppBar>
|
||||
{value === 0 && <TabContainer>
|
||||
<Fragment>
|
||||
<Grid container justify="center">
|
||||
<Quiz quiz={this.easyQuiz} />
|
||||
</Grid>
|
||||
</Fragment>
|
||||
</TabContainer>}
|
||||
{value === 1 && <TabContainer>Medium Quiz</TabContainer>}
|
||||
{value === 2 && <TabContainer>Hard Quiz</TabContainer>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
QuizGame.propTypes = {
|
||||
classes: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default withStyles(styles)(QuizGame);
|
|
@ -1,5 +1,6 @@
|
|||
import firebase from 'firebase/app';
|
||||
import 'firebase/database';
|
||||
import 'firebase/storage';
|
||||
|
||||
const config = {
|
||||
apiKey: "AIzaSyAYf9AbeYwLY892NRiQfn0AMtG9xIFAJbo",
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
import React, { Component } from 'react';
|
||||
import Typography from '@material-ui/core/Typography';
|
||||
|
||||
class Quiz extends Component {
|
||||
render() {
|
||||
return (
|
||||
<Typography variant='display1' align='center' gutterBottom>
|
||||
Quiz
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Quiz;
|
|
@ -0,0 +1,13 @@
|
|||
import React, { Component } from 'react';
|
||||
import QuizGame from '../components/QuizGame';
|
||||
|
||||
|
||||
class QuizPage extends Component {
|
||||
render() {
|
||||
return (
|
||||
<QuizGame />
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default QuizPage;
|
Loading…
Reference in New Issue