浏览代码

questions typeof

amenpunk 2 年之前
父节点
当前提交
b91d4c819e

+ 7 - 7
src/App.css

@@ -288,16 +288,16 @@
288 288
 }
289 289
 .prueba_body{
290 290
   padding: 15px;
291
-  background-color:red;
292
-  width : '100%';
291
+  background: r;
292
+  background-color: red;
293
+  width: '100%';
293 294
   min-height: 95vh;
294
-  display:flex;
295
+  display: flex;
295 296
   flex-direction: column;
296 297
   flex-wrap: nowrap;
297
-  justify-content: center;
298
-  align-items: center;
299
-  align-content: space-around;
300
-}
298
+  align-items: stretch;
299
+  justify-content: flex-start;
300
+  align-content: flex-start;}
301 301
 
302 302
 .quiz_title_text{
303 303
   display: flex;

+ 1 - 1
src/Components/HomeUser/TestCard.jsx

@@ -10,7 +10,7 @@ import { Link } from 'react-router-dom'
10 10
 export function TestCard(props) {
11 11
 
12 12
     let { test } = props;
13
-    console.log('TEST: ', test)
13
+
14 14
     return (
15 15
         <Card className="card_test" elevation={0} sx={{ maxWidth: 500, maxHeight : 500 }}>
16 16
             <CardActionArea>

+ 18 - 0
src/Components/Test/Cleaver/Header.jsx

@@ -0,0 +1,18 @@
1
+import * as React from 'react';
2
+
3
+import CardMedia from '@mui/material/CardMedia';
4
+import Card from '@mui/material/Card';
5
+
6
+export function Header() {
7
+
8
+  return (
9
+    <Card sx={{ display: 'flex' }}>
10
+      <CardMedia
11
+        component="img"
12
+        sx={{ width: '100%', height: 200 }}
13
+        image={"https://static6.depositphotos.com/1000674/642/i/950/depositphotos_6427644-stock-photo-taking-a-test.jpg"}
14
+        alt="Live from space album cover"
15
+      />
16
+    </Card>
17
+  );
18
+}

+ 59 - 38
src/Components/Test/Cleaver/Question.jsx

@@ -6,41 +6,64 @@ import CardContent from '@mui/material/CardContent';
6 6
 import Button from '@mui/material/Button';
7 7
 import Typography from '@mui/material/Typography';
8 8
 import Avatar from '@mui/material/Avatar';
9
-// import Stack from '@mui/material/Stack';
10
-// import Radio from '@mui/material/Radio';
11
-import RadioGroup from '@mui/material/RadioGroup';
12
-import FormControlLabel from '@mui/material/FormControlLabel';
13
-import FormControl from '@mui/material/FormControl';
14
-// import FormLabel from '@mui/material/FormLabel';
15 9
 import Checkbox from '@mui/material/Checkbox';
16 10
 import { deepPurple } from '@mui/material/colors';
17
-const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
18 11
 
12
+import List from '@mui/material/List';
13
+import ListItem from '@mui/material/ListItem';
14
+import ListItemButton from '@mui/material/ListItemButton';
15
+import ListItemIcon from '@mui/material/ListItemIcon';
16
+import ListItemText from '@mui/material/ListItemText';
19 17
 
20
-function Radio() {
21
-  return(
22
-    <div>
23
-    <Checkbox {...label} defaultChecked />
24
-      <Checkbox {...label} />
25
-    </div>
26
-  )
27
-}
18
+function CheckboxesGroup(props) {
19
+
20
+  const [checked, setChecked] = React.useState([0]);
21
+
22
+  const handleToggle = (value) => () => {
23
+    const currentIndex = checked.indexOf(value);
24
+    const newChecked = [...checked];
25
+
26
+    if (currentIndex === -1) {
27
+      newChecked.push(value);
28
+    } else {
29
+      newChecked.splice(currentIndex, 1);
30
+    }
28 31
 
32
+    setChecked(newChecked);
33
+  };
29 34
 
30
-function Response ({resp}) {
31 35
   return (
32
-    <FormControl>
33
-      <RadioGroup
34
-        aria-labelledby="demo-radio-buttons-group-label"
35
-        defaultValue="female"
36
-        name="radio-buttons-group"
37
-      >
38
-        {
39
-        resp.map(a => <FormControlLabel value="female" control={<Radio />} label={a.nombre} />)
40
-        }
41
-      </RadioGroup>
42
-    </FormControl>
43
-  )
36
+    <List sx={{ width: '100%', bgcolor: 'background.paper' }}>
37
+      {props.quiz.map((value) => {
38
+        const labelId = `checkbox-list-label-${value.id}`;
39
+        return (
40
+          <ListItem key={value.id}>
41
+            <ListItemButton role={undefined} onClick={handleToggle(value)} dense>
42
+              <ListItemText id={labelId} primary={value.nombre} />
43
+              <ListItemIcon>
44
+                <Checkbox
45
+                  edge="start"
46
+                  checked={checked.indexOf(value) !== -1}
47
+                  tabIndex={-1}
48
+                  disableRipple
49
+                  inputProps={{ 'aria-labelledby': labelId }}
50
+                  />
51
+              </ListItemIcon>
52
+              <ListItemIcon>
53
+                <Checkbox
54
+                  edge="start"
55
+                  checked={false}
56
+                  tabIndex={-1}
57
+                  disableRipple
58
+                  inputProps={{ 'aria-labelledby': labelId }}
59
+                  />
60
+              </ListItemIcon>
61
+            </ListItemButton>
62
+          </ListItem>
63
+        );
64
+      })}
65
+    </List>
66
+  );
44 67
 }
45 68
 
46 69
 export function Question({ quiz }) {
@@ -49,24 +72,22 @@ export function Question({ quiz }) {
49 72
     <Card sx={{ minWidth: 275, margin: 5 }}>
50 73
       <CardContent>
51 74
 
52
-        <Typography sx={{ fontSize: 17 }} color="text.secondary" gutterBottom>
75
+        <div sx={{ fontSize: 17 }}>
53 76
           <div className="quiz_title_text">
54 77
             <Avatar sx={{ bgcolor: deepPurple[500] }}>{id}</Avatar>
55
-            <p style={{ paddingLeft: 15 }}>
78
+            <Typography style={{ paddingLeft: 15 }}>
56 79
               {instrucciondepregunta}
57
-            </p>
80
+            </Typography>
58 81
           </div>
59
-        </Typography>
60
-
61
-
62
-        <Typography variant="body2">
63
-          <Response resp={respuestas}/>
64
-        </Typography>
82
+        </div>
65 83
 
84
+        <div variant="body2">
85
+          <CheckboxesGroup quiz={respuestas}/>
86
+        </div>
66 87
       </CardContent>
67 88
 
68 89
       <CardActions>
69
-        <Button size="small">Learn More</Button>
90
+        <Button size="small">Siguiente Pregunta</Button>
70 91
       </CardActions>
71 92
 
72 93
     </Card>

+ 6 - 2
src/Pages/Prueba.jsx

@@ -6,6 +6,7 @@ import toast, { Toaster } from 'react-hot-toast';
6 6
 import { useParams } from 'react-router-dom'
7 7
 import useAuth from '../Auth/useAuth.js';
8 8
 import { Cleaver } from './Pruebas/Cleaver';
9
+import { Header } from '../Components/Test/Cleaver/Header';
9 10
 
10 11
 export function Prueba() {
11 12
 
@@ -60,15 +61,18 @@ export function Prueba() {
60 61
   }
61 62
 
62 63
   return (
63
-    <div className="content-section">
64
+    <div  className="content-section">
64 65
       <div className="main">
65 66
         <Box >
67
+          <Paper>
68
+            <Header/>
69
+          </Paper>
66 70
           <Paper className="prueba_body" elevation={1}>
67 71
             <h1>{data?.nombre}</h1>
68 72
             <Divider />
69 73
             <Typography style={{ marginTop: 15, textAlign: 'center' }}>{data?.decription}</Typography>
70 74
             <Divider style={{ marginTop: 15 }} />
71
-            <Button onClick={CreateAssign}>Inicar Prueba</Button>
75
+            <Button  variant="contained" onClick={CreateAssign}>Inicar Prueba</Button>
72 76
           </Paper>
73 77
         </Box>
74 78
         <Toaster

+ 2 - 42
src/Pages/Pruebas/Cleaver.jsx

@@ -1,9 +1,4 @@
1 1
 import React, { useMemo} from 'react'
2
-import {
3
-  Box, 
4
-  // Paper,
5
-  LinearProgress
6
-} from '@mui/material'
7 2
 
8 3
 import { Service } from '../../Utils/HTTP'
9 4
 import useAuth from '../../Auth/useAuth.js';
@@ -15,55 +10,20 @@ export function Cleaver() {
15 10
   let auth = useAuth();
16 11
   let token = useMemo(() => auth.getToken(), [auth])
17 12
 
18
-  const [progress, setProgress] = React.useState(0);
19 13
   const [questions, setQuestions] = React.useState([]);
20
-  const [buffer, setBuffer] = React.useState(10);
21
-
22
-  const progressRef = React.useRef(() => {});
23
-
24 14
   React.useEffect(() => {
25
-
26 15
     let rest = new Service(`/prueba/findid/1`)
27 16
     rest.get(token.toString())
28 17
       .then(({data}) => { 
29
-        console.log("RESP: ", data)
30
-        setQuestions(data.questions)
18
+        setQuestions(data.questions.slice(0,3))
31 19
       })
32 20
       .catch( e => console.log("ERROR: ", e))
33
-
34
-    const timer = setInterval(() => {
35
-      progressRef.current();
36
-    }, 500);
37
-
38
-    return () => {
39
-      clearInterval(timer);
40
-    };
41 21
   }, [token]);
42 22
 
43
-
44
-  React.useEffect(() => {
45
-    progressRef.current = () => {
46
-      if (progress > 100) {
47
-        setProgress(0);
48
-        setBuffer(10);
49
-      } else {
50
-        const diff = Math.random() * 10;
51
-        const diff2 = Math.random() * 10;
52
-        setProgress(progress + diff);
53
-        setBuffer(progress + diff + diff2);
54
-      }
55
-    };
56
-  });
57
-
58 23
   return (
59 24
     <div className="content-section">
60 25
       <div className="main">
61
-        <Box sx={{ width: '100%' , magin : 5}}>
62
-          <LinearProgress style={{ margin : 5}} variant="buffer" value={progress} valueBuffer={buffer} />
63
-        </Box>
64
-        {
65
-        questions.map( e => (<Question key={e.id} quiz={e}/>) )
66
-      }
26
+        { questions.map( (e,i) => (<Question key={i} quiz={e}/>) ) }
67 27
       </div>
68 28
     </div>
69 29
   )

+ 5 - 0
src/Utils/MenuItems.js

@@ -18,6 +18,11 @@ export const UserItems = [
18 18
         route : 'pruebas',
19 19
         title : 'Pruebas'
20 20
     },
21
+    {
22
+        icon : <Star/>,
23
+        route : 'prueba/:id',
24
+        title : 'Test Actual'
25
+    },
21 26
 ]
22 27
 
23 28