浏览代码

progress and store response

amenpunk 2 年之前
父节点
当前提交
3f1ffb7471
共有 3 个文件被更改,包括 30 次插入13 次删除
  1. 1 1
      src/App.css
  2. 18 4
      src/Components/Test/Cleaver/Question.jsx
  3. 11 8
      src/Pages/Pruebas/Cleaver.jsx

+ 1 - 1
src/App.css

349
   grid-row: 1;
349
   grid-row: 1;
350
   min-width: 275;
350
   min-width: 275;
351
   margin: 10px !important; 
351
   margin: 10px !important; 
352
-  border-left: 5px solid var(--main);
352
+  /* border-left: 5px solid var(--main); */
353
 }
353
 }

+ 18 - 4
src/Components/Test/Cleaver/Question.jsx

4
 import {
4
 import {
5
   Card,CardContent,Avatar,Checkbox,List,Tooltip,Fade,
5
   Card,CardContent,Avatar,Checkbox,List,Tooltip,Fade,
6
   ListItem,ListItemButton,ListItemIcon,ListItemText,
6
   ListItem,ListItemButton,ListItemIcon,ListItemText,
7
+  Box,LinearProgress,
7
 } from '@mui/material'
8
 } from '@mui/material'
9
+
8
 import { deepPurple } from '@mui/material/colors';
10
 import { deepPurple } from '@mui/material/colors';
9
 
11
 
12
+function LinearProgressWithLabel(props) {
13
+  return (
14
+    <Box sx={{ display: 'flex', alignItems: 'center' }}>
15
+      <Box sx={{ width: '100%', mr: 0 }}>
16
+        <LinearProgress variant="determinate" {...props} />
17
+      </Box>
18
+    </Box>
19
+  );
20
+}
21
+
10
 function CheckboxexHeader(prop) {
22
 function CheckboxexHeader(prop) {
11
   return (
23
   return (
12
     <List sx={{ width: '100%', bgcolor: 'background.paper' }}>
24
     <List sx={{ width: '100%', bgcolor: 'background.paper' }}>
44
         }
56
         }
45
       }
57
       }
46
       let final = Object.assign(resp,temp);
58
       let final = Object.assign(resp,temp);
47
-      console.log('Change A:',final)
59
+      // console.log('Change A:',final)
48
       save(final)
60
       save(final)
49
     }
61
     }
50
   };
62
   };
60
         }
72
         }
61
       }
73
       }
62
       let final = Object.assign(resp,temp)
74
       let final = Object.assign(resp,temp)
63
-      console.log('Change B: ', final);
75
+      // console.log('Change B: ', final);
64
       save(final)
76
       save(final)
65
     }
77
     }
66
   };
78
   };
119
   );
131
   );
120
 }
132
 }
121
 
133
 
122
-export function Question({quiz, index, current, save, responses}) {
134
+export function Question({quiz, index, current, save, responses, progress}) {
123
   let { instrucciondepregunta, respuestas,id } = quiz
135
   let { instrucciondepregunta, respuestas,id } = quiz
124
   let checked = index === current;
136
   let checked = index === current;
137
+
125
   return (
138
   return (
126
     <Fade in={checked} unmountOnExit>
139
     <Fade in={checked} unmountOnExit>
127
       <Card className="question_form">
140
       <Card className="question_form">
128
         <CardContent>
141
         <CardContent>
129
           <div variant="body2">
142
           <div variant="body2">
130
             <List>
143
             <List>
131
-              <CheckboxexHeader group={id} title={instrucciondepregunta}/>
144
+              <CheckboxexHeader group={index + 1} title={instrucciondepregunta}/>
132
             </List>
145
             </List>
133
             <CheckboxesGroup 
146
             <CheckboxesGroup 
134
               id={id}
147
               id={id}
138
               />
151
               />
139
           </div>
152
           </div>
140
         </CardContent>
153
         </CardContent>
154
+        <LinearProgressWithLabel value={progress} />
141
       </Card>
155
       </Card>
142
     </Fade>
156
     </Fade>
143
   );
157
   );

+ 11 - 8
src/Pages/Pruebas/Cleaver.jsx

14
   const [totalPreguntas, setPreguntas] = React.useState([]);
14
   const [totalPreguntas, setPreguntas] = React.useState([]);
15
   const [current, setCurrent] = React.useState(0);
15
   const [current, setCurrent] = React.useState(0);
16
   const [responses, setRespones] = React.useState({});
16
   const [responses, setRespones] = React.useState({});
17
+  const [progress, setProgress] = React.useState(0);
17
 
18
 
18
-  const BadQuestion = () => toast("Escoge una respuesta en cada columna",{
19
-      icon : '⚠️'
20
-  });
19
+  const BadQuestion = () => toast("Escoge una respuesta en cada columna",{ icon : '⚠️' });
20
+  const CalculateProgress = () => {
21
+    let total_preguntas = totalPreguntas.length + totalRespondidas.length
22
+    let x = totalRespondidas.length *100 / (total_preguntas)
23
+    setProgress(x.toFixed(2))
24
+  }
21
 
25
 
22
   React.useEffect(() => {
26
   React.useEffect(() => {
23
     // TODO:
27
     // TODO:
33
   }, [token]);
37
   }, [token]);
34
 
38
 
35
   const handleAddQuestion = () => {
39
   const handleAddQuestion = () => {
36
-
37
     let currentAnswer  = totalRespondidas[totalRespondidas.length - 1];
40
     let currentAnswer  = totalRespondidas[totalRespondidas.length - 1];
38
     let current_resp = responses[currentAnswer.id];
41
     let current_resp = responses[currentAnswer.id];
39
 
42
 
40
     if(!current_resp){
43
     if(!current_resp){
41
       return BadQuestion();
44
       return BadQuestion();
42
     }
45
     }
43
-    console.log(current_resp)
44
     if(parseInt( current_resp.A ) ===0 || parseInt( current_resp.B ) === 0){
46
     if(parseInt( current_resp.A ) ===0 || parseInt( current_resp.B ) === 0){
45
       return BadQuestion();
47
       return BadQuestion();
46
     }
48
     }
51
       let temp = nextHiddenItem.shift()
53
       let temp = nextHiddenItem.shift()
52
       setRespondidas([...totalRespondidas,temp]);
54
       setRespondidas([...totalRespondidas,temp]);
53
     }
55
     }
56
+    CalculateProgress()
54
   };
57
   };
55
 
58
 
56
   const handleRemoveQuestion = () => {
59
   const handleRemoveQuestion = () => {
59
     let current_without_last = totalRespondidas.filter(({id}) => id !== ultimaRespondida.id);
62
     let current_without_last = totalRespondidas.filter(({id}) => id !== ultimaRespondida.id);
60
     setRespondidas([...current_without_last]);
63
     setRespondidas([...current_without_last]);
61
     setCurrent(current - 1 )
64
     setCurrent(current - 1 )
65
+    CalculateProgress()
62
   }
66
   }
63
 
67
 
64
-  console.log(responses)
65
-
66
   return (
68
   return (
67
     <div  className="content-section question">
69
     <div  className="content-section question">
68
       <Box className="question_body">
70
       <Box className="question_body">
75
             quiz={item} 
77
             quiz={item} 
76
             index={i} 
78
             index={i} 
77
             current={current} 
79
             current={current} 
80
+            progress={progress} 
78
             />)
81
             />)
79
         )}
82
         )}
80
       </Box>
83
       </Box>
100
         </Button>
103
         </Button>
101
       </div>
104
       </div>
102
       <Toaster
105
       <Toaster
103
-        position="top-center"
106
+        position="bottom-right"
104
         />
107
         />
105
     </div>
108
     </div>
106
   )
109
   )