2024-02-14 03:02:15 +00:00
|
|
|
import { Box, Typography, useMediaQuery, useTheme } from "@mui/material";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
import CustomTextField from "@ui_kit/CustomTextField";
|
|
|
|
|
2024-02-12 10:58:51 +00:00
|
|
|
import { updateAnswer, useQuizViewStore } from "@stores/quizView";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2023-12-17 21:28:57 +00:00
|
|
|
import { sendAnswer } from "@api/quizRelase";
|
2024-02-08 13:42:31 +00:00
|
|
|
import { enqueueSnackbar } from "notistack";
|
2023-12-17 22:20:52 +00:00
|
|
|
import { useDebouncedCallback } from "use-debounce";
|
2024-02-08 13:42:31 +00:00
|
|
|
import type { QuizQuestionText } from "../../../model/questionTypes/text";
|
2024-02-14 11:03:35 +00:00
|
|
|
import { useQuizData } from "@contexts/QuizDataContext";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
type TextProps = {
|
2024-02-02 14:35:02 +00:00
|
|
|
currentQuestion: QuizQuestionText;
|
2023-12-16 14:55:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const Text = ({ currentQuestion }: TextProps) => {
|
2024-02-02 14:35:02 +00:00
|
|
|
const theme = useTheme();
|
2024-02-14 11:03:35 +00:00
|
|
|
const { quizId } = useQuizData();
|
2024-02-02 14:35:02 +00:00
|
|
|
const { answers } = useQuizViewStore();
|
2024-02-14 03:02:15 +00:00
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(650));
|
2024-02-02 14:35:02 +00:00
|
|
|
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
const inputHC = useDebouncedCallback(async (text) => {
|
|
|
|
try {
|
2023-12-17 22:20:52 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
await sendAnswer({
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
body: text,
|
2024-02-14 11:03:35 +00:00
|
|
|
qid: quizId,
|
2024-02-02 14:35:02 +00:00
|
|
|
});
|
2023-12-17 22:20:52 +00:00
|
|
|
|
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
} catch (e) {
|
|
|
|
enqueueSnackbar("ответ не был засчитан");
|
|
|
|
}
|
|
|
|
}, 400);
|
|
|
|
return (
|
|
|
|
<Box>
|
2024-02-15 01:20:35 +00:00
|
|
|
<Typography variant="h5" color={theme.palette.text.primary} sx={{wordBreak: "break-word"}}>{currentQuestion.title}</Typography>
|
2024-02-02 14:35:02 +00:00
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
width: "100%",
|
|
|
|
marginTop: "20px",
|
2024-02-14 03:02:15 +00:00
|
|
|
flexDirection: isMobile ? "column-reverse" : undefined,
|
|
|
|
alignItems: "center"
|
2024-02-02 14:35:02 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<CustomTextField
|
|
|
|
placeholder={currentQuestion.content.placeholder}
|
|
|
|
//@ts-ignore
|
|
|
|
value={answer || ""}
|
|
|
|
onChange={async ({ target }) => {
|
2024-02-11 18:04:30 +00:00
|
|
|
updateAnswer(currentQuestion.id, target.value, 0);
|
2024-02-02 14:35:02 +00:00
|
|
|
inputHC(target.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sx={{
|
|
|
|
"&:focus-visible": {
|
|
|
|
borderColor: theme.palette.primary.main
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
2024-02-14 03:02:15 +00:00
|
|
|
{currentQuestion.content.back && currentQuestion.content.back !== " " && (
|
|
|
|
<Box sx={{ maxWidth: "400px", width: "100%", height: "300px", margin: "15px" }}>
|
|
|
|
<img
|
|
|
|
key={currentQuestion.id}
|
|
|
|
src={currentQuestion.content.back}
|
|
|
|
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
2024-02-02 14:35:02 +00:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
2023-12-16 14:55:56 +00:00
|
|
|
};
|