import { Box, Typography, useTheme } from "@mui/material"; import CustomTextField from "@ui_kit/CustomTextField"; import { updateAnswer, useQuizViewStore } from "@stores/quizView"; import { sendAnswer } from "@api/quizRelase"; import { useQuizData } from "@contexts/QuizDataContext"; import { useRootContainerSize } from "@contexts/RootContainerWidthContext"; import { enqueueSnackbar } from "notistack"; import { useState } from "react"; import { useDebouncedCallback } from "use-debounce"; import type { QuizQuestionText } from "../../../model/questionTypes/text"; type TextProps = { currentQuestion: QuizQuestionText; }; export const Text = ({ currentQuestion }: TextProps) => { const theme = useTheme(); const { quizId } = useQuizData(); const { answers } = useQuizViewStore(); const isMobile = useRootContainerSize() < 650; const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {}; const [isSending, setIsSending] = useState(false); const inputHC = useDebouncedCallback(async (text) => { setIsSending(true); try { await sendAnswer({ questionId: currentQuestion.id, body: text, qid: quizId, }); } catch (e) { enqueueSnackbar("ответ не был засчитан"); } setIsSending(false); }, 400); return ( {currentQuestion.title} { updateAnswer(currentQuestion.id, target.value, 0); inputHC(target.value); } } sx={{ "&:focus-visible": { borderColor: theme.palette.primary.main } }} /> {currentQuestion.content.back && currentQuestion.content.back !== " " && ( )} ); };