|
@@ -12,6 +12,7 @@ export function Cleaver() {
|
12
|
12
|
const [totalRespondidas, setRespondidas] = React.useState([]);
|
13
|
13
|
const [totalPreguntas, setPreguntas] = React.useState([]);
|
14
|
14
|
const [current, setCurrent] = React.useState(0);
|
|
15
|
+ const [response, setRespones] = React.useState([]);
|
15
|
16
|
|
16
|
17
|
|
17
|
18
|
React.useEffect(() => {
|
|
@@ -21,22 +22,33 @@ export function Cleaver() {
|
21
|
22
|
console.log(data.questions)
|
22
|
23
|
setPreguntas(data.questions)
|
23
|
24
|
setRespondidas(data.questions.slice(0,1))
|
|
25
|
+ setCurrent(0)
|
24
|
26
|
}).catch(console.log)
|
25
|
27
|
}, [token]);
|
26
|
28
|
|
27
|
29
|
const handleAddQuestion = () => {
|
28
|
|
- // let op = { smooth: true, duration: 200, delay :1, offset :20}
|
29
|
|
- // scroll.scrollToBottom(op);
|
30
|
30
|
let currentAnswer = totalRespondidas[totalRespondidas.length - 1];
|
31
|
31
|
const nextHiddenItem = totalPreguntas.filter(({id}) => id !== currentAnswer.id );
|
32
|
32
|
if (nextHiddenItem) {
|
33
|
33
|
setPreguntas(nextHiddenItem);
|
|
34
|
+ setCurrent(current+1);
|
34
|
35
|
let temp = nextHiddenItem.shift()
|
35
|
36
|
setRespondidas([...totalRespondidas,temp]);
|
36
|
|
- setCurrent(current+1);
|
37
|
37
|
}
|
38
|
38
|
};
|
39
|
39
|
|
|
40
|
+ const handleRemoveQuestion = () => {
|
|
41
|
+ let ultimaRespondida = totalRespondidas[totalRespondidas.length - 1];
|
|
42
|
+ console.log(ultimaRespondida)
|
|
43
|
+ setPreguntas([ultimaRespondida,...totalPreguntas]);
|
|
44
|
+ let current_without_last = totalRespondidas.filter(({id}) => id !== ultimaRespondida.id);
|
|
45
|
+ setRespondidas([...current_without_last]);
|
|
46
|
+ setCurrent(current - 1 )
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ console.log('total respondidas: ', totalRespondidas)
|
|
50
|
+ console.log('total respondidas total: ', totalRespondidas.length)
|
|
51
|
+
|
40
|
52
|
return (
|
41
|
53
|
<div className="content-section question">
|
42
|
54
|
<Box className="question_body">
|
|
@@ -50,8 +62,8 @@ export function Cleaver() {
|
50
|
62
|
className="nextquestion_btn"
|
51
|
63
|
sx={{ backgroundColor: 'var(--main)' }}
|
52
|
64
|
variant="contained"
|
53
|
|
- disabled={totalPreguntas.length <= 0}
|
54
|
|
- onClick={handleAddQuestion}
|
|
65
|
+ disabled={totalRespondidas.length <= 1}
|
|
66
|
+ onClick={handleRemoveQuestion}
|
55
|
67
|
>
|
56
|
68
|
Anterior
|
57
|
69
|
</Button>
|