浏览代码

smooth question render

amenpunk 2 年之前
父节点
当前提交
dc837ad5e8
共有 3 个文件被更改,包括 75 次插入15 次删除
  1. 1 1
      src/App.css
  2. 10 5
      src/Components/Test/Cleaver/Question.jsx
  3. 64 9
      src/Pages/Pruebas/Cleaver.jsx

+ 1 - 1
src/App.css

@@ -308,5 +308,5 @@
308 308
 }
309 309
 
310 310
 .checkbox_label_question{
311
-  font-weight:bold;
311
+  font-weight:bold !important;
312 312
 }

+ 10 - 5
src/Components/Test/Cleaver/Question.jsx

@@ -10,6 +10,7 @@ import Checkbox from '@mui/material/Checkbox';
10 10
 // import { deepPurple } from '@mui/material/colors';
11 11
 
12 12
 import List from '@mui/material/List';
13
+import Tooltip from '@mui/material/Tooltip';
13 14
 import ListItem from '@mui/material/ListItem';
14 15
 import ListItemButton from '@mui/material/ListItemButton';
15 16
 import ListItemIcon from '@mui/material/ListItemIcon';
@@ -42,9 +43,9 @@ function CheckboxesGroup(props) {
42 43
   const [checked, setChecked] = React.useState([0]);
43 44
 
44 45
   const handleToggle = (value) => () => {
46
+
45 47
     const currentIndex = checked.indexOf(value);
46 48
     const newChecked = [...checked];
47
-
48 49
     if (currentIndex === -1) {
49 50
       newChecked.push(value);
50 51
     } else {
@@ -61,7 +62,11 @@ function CheckboxesGroup(props) {
61 62
         return (
62 63
           <ListItem key={value.id}>
63 64
             <ListItemButton role={undefined} onClick={handleToggle(value)} dense>
64
-              <ListItemText className="checkbox_label_question" id={labelId} primary={value.nombre} />
65
+
66
+              <Tooltip title={value.decription} placement="top-start" arrow>
67
+                <ListItemText className="checkbox_label_question" id={labelId} primary={value.nombre} />
68
+              </Tooltip>
69
+
65 70
               <ListItemIcon>
66 71
                 <Checkbox
67 72
                   edge="start"
@@ -74,7 +79,7 @@ function CheckboxesGroup(props) {
74 79
               <ListItemIcon>
75 80
                 <Checkbox
76 81
                   edge="start"
77
-                  checked={false}
82
+                  //checked={}
78 83
                   tabIndex={-1}
79 84
                   disableRipple
80 85
                   inputProps={{ 'aria-labelledby': labelId }}
@@ -89,8 +94,8 @@ function CheckboxesGroup(props) {
89 94
 }
90 95
 
91 96
 export function Question({ quiz }) {
92
-  console.log('quiz: ', quiz)
93
-  let { instrucciondepregunta,respuestas } = quiz
97
+  // console.log('quiz: ', quiz)
98
+  let { instrucciondepregunta, respuestas} = quiz
94 99
   return (
95 100
 
96 101
     <Card sx={{ minWidth: 275, margin: 5 , borderLeft: '5px solid var(--main)'}}>

+ 64 - 9
src/Pages/Pruebas/Cleaver.jsx

@@ -1,29 +1,84 @@
1
-import React, { useMemo} from 'react'
1
+import React, { useMemo, useRef } from 'react'
2 2
 
3 3
 import { Service } from '../../Utils/HTTP'
4 4
 import useAuth from '../../Auth/useAuth.js';
5
-import {Question} from '../../Components/Test/Cleaver/Question.jsx'
5
+import { Question } from '../../Components/Test/Cleaver/Question.jsx'
6 6
 
7
+import Box from '@mui/material/Box';
8
+import Button from '@mui/material/Button';
9
+import Collapse from '@mui/material/Collapse';
10
+import List from '@mui/material/List';
11
+import { TransitionGroup } from 'react-transition-group';
7 12
 
8 13
 export function Cleaver() {
9 14
 
10 15
   let auth = useAuth();
11 16
   let token = useMemo(() => auth.getToken(), [auth])
12 17
 
13
-  const [questions, setQuestions] = React.useState([]);
18
+  const [totalRespondidas, setRespondidas] = React.useState([]);
19
+  const [totalPreguntas, setPreguntas] = React.useState([]);
20
+
21
+
14 22
   React.useEffect(() => {
15 23
     let rest = new Service(`/prueba/findid/1`)
16 24
     rest.get(token.toString())
17
-      .then(({data}) => { 
18
-        setQuestions(data.questions.slice(0,3))
19
-      })
20
-      .catch( e => console.log("ERROR: ", e))
25
+      .then(({ data }) => {
26
+        console.log(data.questions)
27
+        setPreguntas(data.questions)
28
+        setRespondidas(data.questions.slice(0,1))
29
+      }).catch(console.log)
21 30
   }, [token]);
22 31
 
32
+  const handleAddQuestion = () => {
33
+    let currentAnswer  = totalRespondidas[totalRespondidas.length - 1];
34
+    const nextHiddenItem = totalPreguntas.filter(({id}) => id !== currentAnswer.id );
35
+    if (nextHiddenItem) {
36
+      setPreguntas(nextHiddenItem);
37
+      let temp = nextHiddenItem.shift()
38
+      setRespondidas([...totalRespondidas,temp]);
39
+      console.log('RESPONDIDAS: ', totalRespondidas)
40
+      scrollToBottom();
41
+    }
42
+  };
43
+  
44
+  let last = useRef(null)
45
+
46
+const scrollToBottom = () => {
47
+    if(last.current){
48
+      last.current.scrollIntoView()
49
+    }
50
+  }
51
+
52
+  // useEffect(() => {
53
+    // scrollToBottom()
54
+  // }, [totalRespondidas]);
55
+
23 56
   return (
24
-    <div className="content-section">
57
+
58
+    <div  className="content-section">
25 59
       <div className="main">
26
-        { questions.map( (e,i) => (<Question key={i} quiz={e}/>) ) }
60
+        <Box sx={{ mt: 1 }}>
61
+          <List >
62
+            <TransitionGroup >
63
+              {totalRespondidas.map((item) => (
64
+                <Collapse key={item.id} >
65
+                  <Question key={item.id} quiz={item} />
66
+                </Collapse>
67
+              ))
68
+            }
69
+            </TransitionGroup>
70
+          </List>
71
+        </Box>
72
+
73
+      <Button
74
+        ref={last}
75
+        variant="contained"
76
+        disabled={totalRespondidas.length >= totalPreguntas.length}
77
+        onClick={handleAddQuestion}
78
+      >
79
+        Add Question
80
+      </Button>
81
+
27 82
       </div>
28 83
     </div>
29 84
   )