fix: Number required
This commit is contained in:
parent
5987a20843
commit
d95757f79d
@ -56,7 +56,7 @@ useEffect(() => {
|
||||
if (visualStartPage === undefined) return <></>
|
||||
return (
|
||||
<Box>
|
||||
{!visualStartPage ? (
|
||||
{visualStartPage ? (
|
||||
<StartPageViewPublication setVisualStartPage={setVisualStartPage}/>
|
||||
) : (
|
||||
<Question questions={filteredQuestions} />
|
||||
|
@ -8,7 +8,6 @@ import { CustomSlider } from "@ui_kit/CustomSlider";
|
||||
import { useQuizViewStore, updateAnswer } from "@root/quizView";
|
||||
|
||||
import type { QuizQuestionNumber } from "../../../model/questionTypes/number";
|
||||
import {CustomSlider} from "@ui_kit/CustomSlider";
|
||||
|
||||
type NumberProps = {
|
||||
currentQuestion: QuizQuestionNumber;
|
||||
@ -39,27 +38,21 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
||||
},
|
||||
1000
|
||||
);
|
||||
const { answer } =
|
||||
answers.find(
|
||||
({ questionId }) => questionId === currentQuestion.content.id
|
||||
) ?? {};
|
||||
const answer = answers.find(
|
||||
({ questionId }) => questionId === currentQuestion.content.id
|
||||
)?.answer as string;
|
||||
|
||||
const min = window.Number(currentQuestion.content.range.split("—")[0]);
|
||||
const max = window.Number(currentQuestion.content.range.split("—")[1]);
|
||||
const sliderValue = answer || currentQuestion.content.start + "—" + max;
|
||||
|
||||
useEffect(() => {
|
||||
if (answer) {
|
||||
setMinRange(answer.split("—")[0]);
|
||||
setMaxRange(answer.split("—")[1]);
|
||||
}
|
||||
if (!answer) {
|
||||
updateAnswer(
|
||||
currentQuestion.content.id,
|
||||
currentQuestion.content.chooseRange
|
||||
? `${currentQuestion.content.start}—${max}`
|
||||
: String(currentQuestion.content.start)
|
||||
);
|
||||
|
||||
if (!answer) {
|
||||
setMinRange(String(currentQuestion.content.start));
|
||||
setMaxRange(String(max));
|
||||
}
|
||||
@ -80,10 +73,10 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
||||
<CustomSlider
|
||||
value={
|
||||
currentQuestion.content.chooseRange
|
||||
? answer?.split("—").length || 0 > 1
|
||||
? answer?.split("—").map((item) => window.Number(item))
|
||||
? sliderValue.split("—").length || 0 > 1
|
||||
? sliderValue.split("—").map((item) => window.Number(item))
|
||||
: [min, min + 1]
|
||||
: window.Number(answer || 1)
|
||||
: window.Number(sliderValue.split("—")[0])
|
||||
}
|
||||
min={min}
|
||||
max={max}
|
||||
|
Loading…
Reference in New Issue
Block a user