import {Box, TextField, 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 {ChangeEvent, useEffect, useState} from "react"; import { useDebouncedCallback } from "use-debounce"; import type { QuizQuestionText } from "../../../model/questionTypes/text"; type TextProps = { currentQuestion: QuizQuestionText; stepNumber: number | null; }; const Orientation = [ {horizontal: true}, {horizontal: false}, {horizontal: true}, {horizontal: true}, {horizontal: false}, {horizontal: true}, {horizontal: true}, {horizontal: true}, {horizontal: true}, {horizontal: true}, {horizontal: true}, {horizontal: false}, {horizontal: true}, {horizontal: false}, {horizontal: true}, {horizontal: true}, {horizontal: true}, {horizontal: true}, {horizontal: false}, {horizontal: false}, {horizontal: true}, {horizontal: true}, {horizontal: true}, {horizontal: true}, ] export const Text = ({ currentQuestion, stepNumber }: TextProps) => { const theme = useTheme(); const { settings } = useQuizData(); const spec = settings.cfg.spec 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); useEffect( () => () => { inputHC.flush(); }, [inputHC] ); switch (spec) { case true: return ; case undefined: return ; default: return ; } }; interface Props { currentQuestion: QuizQuestionText; answer: any, inputHC: (a: string) => void; stepNumber?: number | null; } const TextNormal = ({currentQuestion, answer, inputHC}: Props) => { const isMobile = useRootContainerSize() < 650; const theme = useTheme(); 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 !== " " && ( )} ) }; const TextSpecial = ({currentQuestion, answer, inputHC, stepNumber}: Props) => { const theme = useTheme(); const isMobile = useRootContainerSize() < 650; const isHorizontal = Orientation[Number(stepNumber) -1].horizontal return( {currentQuestion.title} {isHorizontal && currentQuestion.content.back && currentQuestion.content.back !== " " && ( )} ) => { updateAnswer(currentQuestion.id, target.value, 0); inputHC(target.value); } } inputProps={{maxLength:400}} sx={{ width: "100%", "&:focus-visible": { borderColor: theme.palette.primary.main } }} /> {!isHorizontal && currentQuestion.content.back && currentQuestion.content.back !== " " && ( )} ) }