浏览代码

start save response

amenpunk 2 年之前
父节点
当前提交
fc484abd37
共有 3 个文件被更改,包括 48 次插入19 次删除
  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,6 +330,9 @@
330 330
   padding-bottom:35px;
331 331
   margin-bottom:35px;
332 332
 }
333
+.nextquestion_btn{
334
+  margin-left:5px !important;
335
+}
333 336
 .nextquestion_btn:hover{
334 337
   background-color: var(--main) !important;
335 338
 }

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

@@ -28,29 +28,44 @@ function CheckboxexHeader(prop) {
28 28
 
29 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 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 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 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 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 64
   return (
50 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 69
         const labelId = `checkbox-list-label-${value.id}`;
55 70
 
56 71
         return (
@@ -100,20 +115,23 @@ function CheckboxesGroup(props) {
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 120
   let checked = index === current;
106
-  // console.log("QUESTION INDEX: ",index)
107
-  // console.log("Checked: ",checked)
108 121
   return (
109 122
     <Fade in={checked} unmountOnExit>
110 123
       <Card className="question_form">
111 124
         <CardContent>
112 125
           <div variant="body2">
113 126
             <List>
114
-              <CheckboxexHeader group={id} title={instrucciondepregunta}/>
127
+              <CheckboxexHeader group={index + 1} title={instrucciondepregunta}/>
115 128
             </List>
116
-            <CheckboxesGroup quiz={respuestas} />
129
+            <CheckboxesGroup 
130
+              id={id}
131
+              quiz={respuestas} 
132
+              save={save}
133
+              responses={responses}
134
+              />
117 135
           </div>
118 136
         </CardContent>
119 137
       </Card>

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

@@ -12,10 +12,12 @@ export function Cleaver() {
12 12
   const [totalRespondidas, setRespondidas] = React.useState([]);
13 13
   const [totalPreguntas, setPreguntas] = React.useState([]);
14 14
   const [current, setCurrent] = React.useState(0);
15
-  const [response, setRespones] = React.useState([]);
15
+  const [responses, setRespones] = React.useState({});
16 16
 
17 17
 
18 18
   React.useEffect(() => {
19
+    // TODO:
20
+    // agregar el id correcto apartir del path
19 21
     let rest = new Service(`/prueba/findid/1`)
20 22
     rest.get(token.toString())
21 23
       .then(({ data }) => {
@@ -39,21 +41,27 @@ export function Cleaver() {
39 41
 
40 42
   const handleRemoveQuestion = () => {
41 43
     let ultimaRespondida = totalRespondidas[totalRespondidas.length - 1];
42
-    console.log(ultimaRespondida)
43 44
     setPreguntas([ultimaRespondida,...totalPreguntas]);
44 45
     let current_without_last = totalRespondidas.filter(({id}) => id !== ultimaRespondida.id);
45 46
     setRespondidas([...current_without_last]);
46 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 52
   return (
53 53
     <div  className="content-section question">
54 54
       <Box className="question_body">
55 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 66
       </Box>
59 67