Browse Source

smooth question render

amenpunk 2 years ago
parent
commit
dc837ad5e8
3 changed files with 75 additions and 15 deletions
  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
 }
308
 }
309
 
309
 
310
 .checkbox_label_question{
310
 .checkbox_label_question{
311
-  font-weight:bold;
311
+  font-weight:bold !important;
312
 }
312
 }

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

10
 // import { deepPurple } from '@mui/material/colors';
10
 // import { deepPurple } from '@mui/material/colors';
11
 
11
 
12
 import List from '@mui/material/List';
12
 import List from '@mui/material/List';
13
+import Tooltip from '@mui/material/Tooltip';
13
 import ListItem from '@mui/material/ListItem';
14
 import ListItem from '@mui/material/ListItem';
14
 import ListItemButton from '@mui/material/ListItemButton';
15
 import ListItemButton from '@mui/material/ListItemButton';
15
 import ListItemIcon from '@mui/material/ListItemIcon';
16
 import ListItemIcon from '@mui/material/ListItemIcon';
42
   const [checked, setChecked] = React.useState([0]);
43
   const [checked, setChecked] = React.useState([0]);
43
 
44
 
44
   const handleToggle = (value) => () => {
45
   const handleToggle = (value) => () => {
46
+
45
     const currentIndex = checked.indexOf(value);
47
     const currentIndex = checked.indexOf(value);
46
     const newChecked = [...checked];
48
     const newChecked = [...checked];
47
-
48
     if (currentIndex === -1) {
49
     if (currentIndex === -1) {
49
       newChecked.push(value);
50
       newChecked.push(value);
50
     } else {
51
     } else {
61
         return (
62
         return (
62
           <ListItem key={value.id}>
63
           <ListItem key={value.id}>
63
             <ListItemButton role={undefined} onClick={handleToggle(value)} dense>
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
               <ListItemIcon>
70
               <ListItemIcon>
66
                 <Checkbox
71
                 <Checkbox
67
                   edge="start"
72
                   edge="start"
74
               <ListItemIcon>
79
               <ListItemIcon>
75
                 <Checkbox
80
                 <Checkbox
76
                   edge="start"
81
                   edge="start"
77
-                  checked={false}
82
+                  //checked={}
78
                   tabIndex={-1}
83
                   tabIndex={-1}
79
                   disableRipple
84
                   disableRipple
80
                   inputProps={{ 'aria-labelledby': labelId }}
85
                   inputProps={{ 'aria-labelledby': labelId }}
89
 }
94
 }
90
 
95
 
91
 export function Question({ quiz }) {
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
   return (
99
   return (
95
 
100
 
96
     <Card sx={{ minWidth: 275, margin: 5 , borderLeft: '5px solid var(--main)'}}>
101
     <Card sx={{ minWidth: 275, margin: 5 , borderLeft: '5px solid var(--main)'}}>

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

1
-import React, { useMemo} from 'react'
1
+import React, { useMemo, useRef } from 'react'
2
 
2
 
3
 import { Service } from '../../Utils/HTTP'
3
 import { Service } from '../../Utils/HTTP'
4
 import useAuth from '../../Auth/useAuth.js';
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
 export function Cleaver() {
13
 export function Cleaver() {
9
 
14
 
10
   let auth = useAuth();
15
   let auth = useAuth();
11
   let token = useMemo(() => auth.getToken(), [auth])
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
   React.useEffect(() => {
22
   React.useEffect(() => {
15
     let rest = new Service(`/prueba/findid/1`)
23
     let rest = new Service(`/prueba/findid/1`)
16
     rest.get(token.toString())
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
   }, [token]);
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
   return (
56
   return (
24
-    <div className="content-section">
57
+
58
+    <div  className="content-section">
25
       <div className="main">
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
       </div>
82
       </div>
28
     </div>
83
     </div>
29
   )
84
   )