|
@@ -2,20 +2,23 @@ import React from 'react'
|
|
|
import { Service } from '../../Utils/HTTP'
|
|
import { Service } from '../../Utils/HTTP'
|
|
|
import { Question } from '../../Components/Test/Cleaver/Question.jsx'
|
|
import { Question } from '../../Components/Test/Cleaver/Question.jsx'
|
|
|
import { Box,Button } from '@mui/material'
|
|
import { Box,Button } from '@mui/material'
|
|
|
-import toast, { Toaster } from 'react-hot-toast';
|
|
|
|
|
import { useSelector } from 'react-redux';
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
+import { useParams } from 'react-router-dom'
|
|
|
|
|
+import toast, { Toaster } from 'react-hot-toast';
|
|
|
|
|
|
|
|
export function Cleaver() {
|
|
export function Cleaver() {
|
|
|
|
|
|
|
|
- let token = useSelector((state) => state.token.token);
|
|
|
|
|
|
|
+ let { id } = useParams();
|
|
|
|
|
+ const auth = useSelector((state) => state.token.token);
|
|
|
|
|
+ const cleaver = useSelector((state) => state.cleaver);
|
|
|
|
|
|
|
|
const [totalRespondidas, setRespondidas] = React.useState([]);
|
|
const [totalRespondidas, setRespondidas] = React.useState([]);
|
|
|
const [totalPreguntas, setPreguntas] = React.useState([]);
|
|
const [totalPreguntas, setPreguntas] = React.useState([]);
|
|
|
const [current, setCurrent] = React.useState(0);
|
|
const [current, setCurrent] = React.useState(0);
|
|
|
- const [responses, setRespones] = React.useState({});
|
|
|
|
|
const [progress, setProgress] = React.useState(0);
|
|
const [progress, setProgress] = React.useState(0);
|
|
|
|
|
|
|
|
- const BadQuestion = () => toast("Escoge una respuesta en cada columna",{ icon : '⚠️' });
|
|
|
|
|
|
|
+ const BadQuestion = () => toast.error("Escoge una respuesta en cada columna")
|
|
|
|
|
+ //toast("Escoge una respuesta en cada columna",{ icon : '⚠️' });
|
|
|
const CalculateProgress = () => {
|
|
const CalculateProgress = () => {
|
|
|
let total_preguntas = totalPreguntas.length + totalRespondidas.length
|
|
let total_preguntas = totalPreguntas.length + totalRespondidas.length
|
|
|
let x = totalRespondidas.length *100 / (total_preguntas)
|
|
let x = totalRespondidas.length *100 / (total_preguntas)
|
|
@@ -23,21 +26,19 @@ export function Cleaver() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
React.useEffect(() => {
|
|
|
- // TODO:
|
|
|
|
|
- // agregar el id correcto apartir del path
|
|
|
|
|
- let rest = new Service(`/prueba/findid/1`)
|
|
|
|
|
- rest.get(token.token)
|
|
|
|
|
|
|
+ let rest = new Service(`/prueba/findid/${id}`)
|
|
|
|
|
+ rest.get(auth.token)
|
|
|
.then(({ data }) => {
|
|
.then(({ data }) => {
|
|
|
console.log(data.questions)
|
|
console.log(data.questions)
|
|
|
setPreguntas(data.questions)
|
|
setPreguntas(data.questions)
|
|
|
setRespondidas(data.questions.slice(0,1))
|
|
setRespondidas(data.questions.slice(0,1))
|
|
|
setCurrent(0)
|
|
setCurrent(0)
|
|
|
}).catch(console.log)
|
|
}).catch(console.log)
|
|
|
- }, [token]);
|
|
|
|
|
|
|
+ }, [id,auth]);
|
|
|
|
|
|
|
|
const handleAddQuestion = () => {
|
|
const handleAddQuestion = () => {
|
|
|
let currentAnswer = totalRespondidas[totalRespondidas.length - 1];
|
|
let currentAnswer = totalRespondidas[totalRespondidas.length - 1];
|
|
|
- let current_resp = responses[currentAnswer.id];
|
|
|
|
|
|
|
+ let current_resp = cleaver.responses[currentAnswer.id];
|
|
|
|
|
|
|
|
if(!current_resp){
|
|
if(!current_resp){
|
|
|
return BadQuestion();
|
|
return BadQuestion();
|
|
@@ -69,8 +70,6 @@ export function Cleaver() {
|
|
|
<Box className="question_body">
|
|
<Box className="question_body">
|
|
|
{totalRespondidas.map((item,i) => (
|
|
{totalRespondidas.map((item,i) => (
|
|
|
<Question
|
|
<Question
|
|
|
- save={setRespones}
|
|
|
|
|
- responses={responses}
|
|
|
|
|
key={item.id}
|
|
key={item.id}
|
|
|
id={item.id}
|
|
id={item.id}
|
|
|
quiz={item}
|
|
quiz={item}
|