浏览代码

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

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

@@ -14,10 +14,14 @@ export function Cleaver() {
14 14
   const [totalPreguntas, setPreguntas] = React.useState([]);
15 15
   const [current, setCurrent] = React.useState(0);
16 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 26
   React.useEffect(() => {
23 27
     // TODO:
@@ -33,14 +37,12 @@ export function Cleaver() {
33 37
   }, [token]);
34 38
 
35 39
   const handleAddQuestion = () => {
36
-
37 40
     let currentAnswer  = totalRespondidas[totalRespondidas.length - 1];
38 41
     let current_resp = responses[currentAnswer.id];
39 42
 
40 43
     if(!current_resp){
41 44
       return BadQuestion();
42 45
     }
43
-    console.log(current_resp)
44 46
     if(parseInt( current_resp.A ) ===0 || parseInt( current_resp.B ) === 0){
45 47
       return BadQuestion();
46 48
     }
@@ -51,6 +53,7 @@ export function Cleaver() {
51 53
       let temp = nextHiddenItem.shift()
52 54
       setRespondidas([...totalRespondidas,temp]);
53 55
     }
56
+    CalculateProgress()
54 57
   };
55 58
 
56 59
   const handleRemoveQuestion = () => {
@@ -59,10 +62,9 @@ export function Cleaver() {
59 62
     let current_without_last = totalRespondidas.filter(({id}) => id !== ultimaRespondida.id);
60 63
     setRespondidas([...current_without_last]);
61 64
     setCurrent(current - 1 )
65
+    CalculateProgress()
62 66
   }
63 67
 
64
-  console.log(responses)
65
-
66 68
   return (
67 69
     <div  className="content-section question">
68 70
       <Box className="question_body">
@@ -75,6 +77,7 @@ export function Cleaver() {
75 77
             quiz={item} 
76 78
             index={i} 
77 79
             current={current} 
80
+            progress={progress} 
78 81
             />)
79 82
         )}
80 83
       </Box>
@@ -100,7 +103,7 @@ export function Cleaver() {
100 103
         </Button>
101 104
       </div>
102 105
       <Toaster
103
-        position="top-center"
106
+        position="bottom-right"
104 107
         />
105 108
     </div>
106 109
   )