|
@@ -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
|
)
|