Browse Source

start save response

amenpunk 2 years ago
parent
commit
fc484abd37
3 changed files with 48 additions and 19 deletions
  1. 3 0
      src/App.css
  2. 32 14
      src/Components/Test/Cleaver/Question.jsx
  3. 13 5
      src/Pages/Pruebas/Cleaver.jsx

+ 3 - 0
src/App.css

330
   padding-bottom:35px;
330
   padding-bottom:35px;
331
   margin-bottom:35px;
331
   margin-bottom:35px;
332
 }
332
 }
333
+.nextquestion_btn{
334
+  margin-left:5px !important;
335
+}
333
 .nextquestion_btn:hover{
336
 .nextquestion_btn:hover{
334
   background-color: var(--main) !important;
337
   background-color: var(--main) !important;
335
 }
338
 }

+ 32 - 14
src/Components/Test/Cleaver/Question.jsx

28
 
28
 
29
 function CheckboxesGroup(props) {
29
 function CheckboxesGroup(props) {
30
 
30
 
31
-  const [checkA, setCheckA] = React.useState(0);
32
-  const [checkB, setCheckB] = React.useState(0);
31
+  let { quiz, save, responses : resp, id:index} = props;
33
 
32
 
33
+  const [checkA, setCheckA] = React.useState( 0);
34
+  const [checkB, setCheckB] = React.useState(0);
34
 
35
 
35
   const changeA = (event) => {
36
   const changeA = (event) => {
36
-    let { id } = event.target
37
-    if(parseInt( checkB ) !== parseInt(id) ){
37
+    let { id, checked } = event.target
38
+    if(parseInt( checkB ) !== parseInt(id) && checked ){
38
       setCheckA(parseInt( id ))
39
       setCheckA(parseInt( id ))
40
+      let temp = {
41
+        [index]: {
42
+          A:id,
43
+          B: resp[id]?.B ? resp[id].B : 0
44
+        }
45
+      }
46
+      save(Object.assign(resp,temp))
39
     }
47
     }
40
   };
48
   };
41
   
49
   
42
   const changeB = (event) => {
50
   const changeB = (event) => {
43
-    let { id } = event.target
44
-    if(parseInt( checkA ) !== parseInt( id )){
51
+    let { id, checked } = event.target
52
+    if(parseInt( checkA ) !== parseInt( id ) && checked){
45
       setCheckB(parseInt( id ))
53
       setCheckB(parseInt( id ))
54
+      let temp = {
55
+        [index]: {
56
+          B:id,
57
+          A: resp[id]?.A ? resp[id].A : 0
58
+        }
59
+      }
60
+      save(Object.assign(resp,temp))
46
     }
61
     }
47
   };
62
   };
48
 
63
 
49
   return (
64
   return (
50
     <List sx={{ width: '100%', bgcolor: 'background.paper' }}>
65
     <List sx={{ width: '100%', bgcolor: 'background.paper' }}>
51
 
66
 
52
-      {props.quiz.map((value) => {
53
-
67
+      {quiz.map((value) => {
68
+        // console.log("QUIZ VALUE: ", value)
54
         const labelId = `checkbox-list-label-${value.id}`;
69
         const labelId = `checkbox-list-label-${value.id}`;
55
 
70
 
56
         return (
71
         return (
100
   );
115
   );
101
 }
116
 }
102
 
117
 
103
-export function Question({quiz, index, current}) {
104
-  let { instrucciondepregunta, respuestas,id} = quiz
118
+export function Question({quiz, index, current, save, responses}) {
119
+  let { instrucciondepregunta, respuestas,id } = quiz
105
   let checked = index === current;
120
   let checked = index === current;
106
-  // console.log("QUESTION INDEX: ",index)
107
-  // console.log("Checked: ",checked)
108
   return (
121
   return (
109
     <Fade in={checked} unmountOnExit>
122
     <Fade in={checked} unmountOnExit>
110
       <Card className="question_form">
123
       <Card className="question_form">
111
         <CardContent>
124
         <CardContent>
112
           <div variant="body2">
125
           <div variant="body2">
113
             <List>
126
             <List>
114
-              <CheckboxexHeader group={id} title={instrucciondepregunta}/>
127
+              <CheckboxexHeader group={index + 1} title={instrucciondepregunta}/>
115
             </List>
128
             </List>
116
-            <CheckboxesGroup quiz={respuestas} />
129
+            <CheckboxesGroup 
130
+              id={id}
131
+              quiz={respuestas} 
132
+              save={save}
133
+              responses={responses}
134
+              />
117
           </div>
135
           </div>
118
         </CardContent>
136
         </CardContent>
119
       </Card>
137
       </Card>

+ 13 - 5
src/Pages/Pruebas/Cleaver.jsx

12
   const [totalRespondidas, setRespondidas] = React.useState([]);
12
   const [totalRespondidas, setRespondidas] = React.useState([]);
13
   const [totalPreguntas, setPreguntas] = React.useState([]);
13
   const [totalPreguntas, setPreguntas] = React.useState([]);
14
   const [current, setCurrent] = React.useState(0);
14
   const [current, setCurrent] = React.useState(0);
15
-  const [response, setRespones] = React.useState([]);
15
+  const [responses, setRespones] = React.useState({});
16
 
16
 
17
 
17
 
18
   React.useEffect(() => {
18
   React.useEffect(() => {
19
+    // TODO:
20
+    // agregar el id correcto apartir del path
19
     let rest = new Service(`/prueba/findid/1`)
21
     let rest = new Service(`/prueba/findid/1`)
20
     rest.get(token.toString())
22
     rest.get(token.toString())
21
       .then(({ data }) => {
23
       .then(({ data }) => {
39
 
41
 
40
   const handleRemoveQuestion = () => {
42
   const handleRemoveQuestion = () => {
41
     let ultimaRespondida = totalRespondidas[totalRespondidas.length - 1];
43
     let ultimaRespondida = totalRespondidas[totalRespondidas.length - 1];
42
-    console.log(ultimaRespondida)
43
     setPreguntas([ultimaRespondida,...totalPreguntas]);
44
     setPreguntas([ultimaRespondida,...totalPreguntas]);
44
     let current_without_last = totalRespondidas.filter(({id}) => id !== ultimaRespondida.id);
45
     let current_without_last = totalRespondidas.filter(({id}) => id !== ultimaRespondida.id);
45
     setRespondidas([...current_without_last]);
46
     setRespondidas([...current_without_last]);
46
     setCurrent(current - 1 )
47
     setCurrent(current - 1 )
47
   }
48
   }
48
 
49
 
49
-  console.log('total respondidas: ', totalRespondidas)
50
-  console.log('total respondidas total: ', totalRespondidas.length)
50
+  console.log(responses)
51
 
51
 
52
   return (
52
   return (
53
     <div  className="content-section question">
53
     <div  className="content-section question">
54
       <Box className="question_body">
54
       <Box className="question_body">
55
         {totalRespondidas.map((item,i) => (
55
         {totalRespondidas.map((item,i) => (
56
-          <Question key={item.id} id={item.id} quiz={item} index={i} current={current} /> )
56
+          <Question 
57
+            save={setRespones}
58
+            responses={responses}
59
+            key={item.id} 
60
+            id={item.id} 
61
+            quiz={item} 
62
+            index={i} 
63
+            current={current} 
64
+            />)
57
         )}
65
         )}
58
       </Box>
66
       </Box>
59
 
67