import { useEffect } from "react"; import { Box, Typography, Slider, useTheme } from "@mui/material"; import CustomTextField from "@ui_kit/CustomTextField"; import { useQuizViewStore, updateAnswer } from "@root/quizView"; import type { QuizQuestionNumber } from "../../../model/questionTypes/number"; type NumberProps = { currentQuestion: QuizQuestionNumber; }; export const Number = ({ currentQuestion }: NumberProps) => { const theme = useTheme(); const { answers } = useQuizViewStore(); const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.content.id) ?? {}; const min = window.Number(currentQuestion.content.range.split("—")[0]); const max = window.Number(currentQuestion.content.range.split("—")[1]); useEffect(() => { if (!answer) { updateAnswer(currentQuestion.content.id, "1"); } }, []); return ( {currentQuestion.title} { updateAnswer( currentQuestion.content.id, window.Number(target.value) > max ? String(max) : window.Number(target.value) < min ? String(min) : target.value ); }} sx={{ maxWidth: "80px", "& .MuiInputBase-input": { textAlign: "center" }, }} /> { updateAnswer(currentQuestion.content.id, String(value)); }} /> ); };