|
|
@@ -28,29 +28,44 @@ function CheckboxexHeader(prop) {
|
|
|
|
|
|
function CheckboxesGroup(props) {
|
|
|
|
|
|
- const [checkA, setCheckA] = React.useState(0);
|
|
|
- const [checkB, setCheckB] = React.useState(0);
|
|
|
+ let { quiz, save, responses : resp, id:index} = props;
|
|
|
|
|
|
+ const [checkA, setCheckA] = React.useState( 0);
|
|
|
+ const [checkB, setCheckB] = React.useState(0);
|
|
|
|
|
|
const changeA = (event) => {
|
|
|
- let { id } = event.target
|
|
|
- if(parseInt( checkB ) !== parseInt(id) ){
|
|
|
+ let { id, checked } = event.target
|
|
|
+ if(parseInt( checkB ) !== parseInt(id) && checked ){
|
|
|
setCheckA(parseInt( id ))
|
|
|
+ let temp = {
|
|
|
+ [index]: {
|
|
|
+ A:id,
|
|
|
+ B: resp[id]?.B ? resp[id].B : 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ save(Object.assign(resp,temp))
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const changeB = (event) => {
|
|
|
- let { id } = event.target
|
|
|
- if(parseInt( checkA ) !== parseInt( id )){
|
|
|
+ let { id, checked } = event.target
|
|
|
+ if(parseInt( checkA ) !== parseInt( id ) && checked){
|
|
|
setCheckB(parseInt( id ))
|
|
|
+ let temp = {
|
|
|
+ [index]: {
|
|
|
+ B:id,
|
|
|
+ A: resp[id]?.A ? resp[id].A : 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ save(Object.assign(resp,temp))
|
|
|
}
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
<List sx={{ width: '100%', bgcolor: 'background.paper' }}>
|
|
|
|
|
|
- {props.quiz.map((value) => {
|
|
|
-
|
|
|
+ {quiz.map((value) => {
|
|
|
+ // console.log("QUIZ VALUE: ", value)
|
|
|
const labelId = `checkbox-list-label-${value.id}`;
|
|
|
|
|
|
return (
|
|
|
@@ -100,20 +115,23 @@ function CheckboxesGroup(props) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-export function Question({quiz, index, current}) {
|
|
|
- let { instrucciondepregunta, respuestas,id} = quiz
|
|
|
+export function Question({quiz, index, current, save, responses}) {
|
|
|
+ let { instrucciondepregunta, respuestas,id } = quiz
|
|
|
let checked = index === current;
|
|
|
- // console.log("QUESTION INDEX: ",index)
|
|
|
- // console.log("Checked: ",checked)
|
|
|
return (
|
|
|
<Fade in={checked} unmountOnExit>
|
|
|
<Card className="question_form">
|
|
|
<CardContent>
|
|
|
<div variant="body2">
|
|
|
<List>
|
|
|
- <CheckboxexHeader group={id} title={instrucciondepregunta}/>
|
|
|
+ <CheckboxexHeader group={index + 1} title={instrucciondepregunta}/>
|
|
|
</List>
|
|
|
- <CheckboxesGroup quiz={respuestas} />
|
|
|
+ <CheckboxesGroup
|
|
|
+ id={id}
|
|
|
+ quiz={respuestas}
|
|
|
+ save={save}
|
|
|
+ responses={responses}
|
|
|
+ />
|
|
|
</div>
|
|
|
</CardContent>
|
|
|
</Card>
|