-
Notifications
You must be signed in to change notification settings - Fork 35
💡Good to provide incorrect answers at the end of the game #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
20ab736
7aaa3dd
14a2f34
a050803
0f40fcc
937bffe
179d7c5
a8b77eb
78de8fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ const patterns = [ | |
codeES5: 'Code ES5 - Prototype', | ||
codeES6: 'Code ES6 - Prototype', | ||
answered: false, | ||
answerId: null, | ||
correct: null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡I want to discuss the field |
||
}, | ||
|
||
|
@@ -29,7 +28,6 @@ const patterns = [ | |
codeES5: 'Code ES5 - Singleton', | ||
codeES6: 'Code ES6 - Singleton', | ||
answered: false, | ||
answerId: null, | ||
correct: null | ||
} | ||
]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,20 +28,19 @@ const StyledButton = styled.button` | |
} | ||
`; | ||
|
||
export const Button = props => { | ||
const { id, label, onClick } = props; | ||
|
||
return ( | ||
<StyledButton id={id} onClick={onClick}> | ||
{label && <span>{label}</span>} | ||
</StyledButton> | ||
); | ||
}; | ||
export const Button = ({ id, label, onClick = () => {}, theme = {} }) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
<StyledButton id={id} onClick={onClick} theme={theme}> | ||
{label && <span>{label}</span>} | ||
</StyledButton> | ||
); | ||
|
||
Button.propTypes = { | ||
label: PropTypes.string.isRequired, | ||
id: PropTypes.string.isRequired, | ||
onClick: PropTypes.func.isRequired | ||
label: PropTypes.string.isRequired, | ||
onClick: PropTypes.func, | ||
theme: PropTypes.shape({ | ||
buttonBackground: PropTypes.string | ||
}) | ||
}; | ||
|
||
export default Button; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,7 @@ import styled from 'styled-components'; | |
import { connect } from 'react-redux'; | ||
import Button from './Button'; | ||
import { submitAnswer } from '../actions/submitAnswer'; | ||
import { getCurrent, getPatterns } from '../selectors'; | ||
import { shuffle } from '../helpers/shuffleArray'; | ||
import { getCurrent } from '../selectors'; | ||
|
||
const StyledButtonContainer = styled.div` | ||
align-content: space-around; | ||
|
@@ -16,34 +15,22 @@ const StyledButtonContainer = styled.div` | |
margin: 1rem 0 2rem; | ||
`; | ||
|
||
export const ButtonContainer = props => { | ||
const { current, patterns, onSubmitAnswer } = props; | ||
|
||
// get 3 random patterns in addition to correct one | ||
const allOtherAnswers = patterns.filter(pattern => pattern.uuid !== current.uuid); | ||
const additional = shuffle(allOtherAnswers).slice(0, 3); | ||
// shuffle the 4 answers | ||
const variants = shuffle([current, ...additional]); | ||
|
||
return ( | ||
<StyledButtonContainer> | ||
{variants.map(({ uuid, name }) => ( | ||
<Button label={name} id={uuid} key={uuid} onClick={() => onSubmitAnswer(uuid)} /> | ||
))} | ||
</StyledButtonContainer> | ||
); | ||
}; | ||
export const ButtonContainer = ({ current, onSubmitAnswer }) => ( | ||
<StyledButtonContainer> | ||
{current.variants.map(({ uuid, name }) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved all the logic below |
||
<Button label={name} id={uuid} key={uuid} onClick={() => onSubmitAnswer(uuid)} /> | ||
))} | ||
</StyledButtonContainer> | ||
); | ||
|
||
ButtonContainer.propTypes = { | ||
patterns: PropTypes.array.isRequired, | ||
current: PropTypes.object.isRequired, | ||
onSubmitAnswer: PropTypes.func.isRequired | ||
}; | ||
|
||
export default connect( | ||
state => ({ | ||
current: getCurrent(state), | ||
patterns: getPatterns(state) | ||
current: getCurrent(state) | ||
}), | ||
{ | ||
onSubmitAnswer: id => submitAnswer(id) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { getAnswers, getPatterns } from '../selectors'; | ||
import IncorrectCode from './IncorrectCode'; | ||
|
||
export const IncorrectAnswers = ({ answers, style }) => { | ||
const incorrectAnswers = answers.filter(answer => !answer.correct); | ||
|
||
return incorrectAnswers.map(({ uuid }) => ( | ||
<IncorrectCode key={uuid} uuid={uuid} style={style} /> | ||
)); | ||
}; | ||
|
||
IncorrectAnswers.propTypes = { | ||
answers: PropTypes.array.isRequired, | ||
style: PropTypes.object.isRequired | ||
}; | ||
|
||
export default connect(state => ({ | ||
answers: getAnswers(state), | ||
patterns: getPatterns(state) | ||
}))(IncorrectAnswers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
answerId
is same asuuid
in the store