2023-12-16 14:55:56 +00:00
|
|
|
import {
|
2024-02-02 12:46:38 +00:00
|
|
|
Box,
|
|
|
|
FormControlLabel,
|
|
|
|
Radio,
|
2024-02-05 10:10:02 +00:00
|
|
|
RadioGroup,
|
|
|
|
Typography,
|
|
|
|
useTheme
|
2023-12-16 14:55:56 +00:00
|
|
|
} from "@mui/material";
|
2024-02-12 10:58:51 +00:00
|
|
|
import { deleteAnswer, updateAnswer, useQuizViewStore } from "@stores/quizView";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
import RadioCheck from "@ui_kit/RadioCheck";
|
|
|
|
import RadioIcon from "@ui_kit/RadioIcon";
|
|
|
|
|
2023-12-17 21:28:57 +00:00
|
|
|
import { sendAnswer } from "@api/quizRelase";
|
2024-02-02 12:46:38 +00:00
|
|
|
import BlankImage from "@icons/BlankImage";
|
2024-02-14 11:03:35 +00:00
|
|
|
import { useQuizData } from "@contexts/QuizDataContext";
|
2024-02-05 10:10:02 +00:00
|
|
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
import { useRootContainerSize } from "../../../contexts/RootContainerWidthContext";
|
|
|
|
import type { QuizQuestionVarImg } from "../../../model/questionTypes/varimg";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
type VarimgProps = {
|
2024-02-02 12:46:38 +00:00
|
|
|
currentQuestion: QuizQuestionVarImg;
|
2023-12-16 14:55:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
2024-02-14 11:03:35 +00:00
|
|
|
const { settings, quizId } = useQuizData();
|
2024-02-02 12:46:38 +00:00
|
|
|
const { answers } = useQuizViewStore();
|
|
|
|
const theme = useTheme();
|
2024-02-05 10:10:02 +00:00
|
|
|
const isMobile = useRootContainerSize() < 650;
|
2024-02-02 12:46:38 +00:00
|
|
|
|
|
|
|
const { answer } =
|
|
|
|
answers.find(
|
|
|
|
({ questionId }) => questionId === currentQuestion.id
|
|
|
|
) ?? {};
|
|
|
|
const variant = currentQuestion.content.variants.find(
|
|
|
|
({ id }) => answer === id
|
|
|
|
);
|
|
|
|
|
|
|
|
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 12:46:38 +00:00
|
|
|
<Box sx={{
|
|
|
|
display: "flex",
|
|
|
|
marginTop: "20px",
|
|
|
|
flexDirection: isMobile ? "column-reverse" : undefined,
|
2024-02-13 22:45:27 +00:00
|
|
|
gap: isMobile ? "30px" : undefined,
|
|
|
|
alignItems: isMobile ? "center" : undefined
|
2024-02-02 12:46:38 +00:00
|
|
|
|
|
|
|
}}>
|
|
|
|
<RadioGroup
|
|
|
|
name={currentQuestion.id}
|
|
|
|
value={currentQuestion.content.variants.findIndex(
|
|
|
|
({ id }) => answer === id
|
|
|
|
)}
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexWrap: "wrap",
|
|
|
|
flexDirection: "row",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
flexBasis: "100%",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box sx={{ display: "flex", flexDirection: "column", width: "100%", gap: isMobile ? "20px" : undefined }}>
|
|
|
|
{currentQuestion.content.variants.map((variant, index) => (
|
|
|
|
<FormControlLabel
|
|
|
|
key={variant.id}
|
|
|
|
sx={{
|
|
|
|
marginBottom: "15px",
|
|
|
|
borderRadius: "5px",
|
|
|
|
padding: "15px",
|
|
|
|
color: theme.palette.text.primary,
|
|
|
|
backgroundColor: quizThemes[settings.cfg.theme].isLight ? "white" : theme.palette.background.default,
|
|
|
|
border: `1px solid`,
|
|
|
|
borderColor: answer === variant.id ? theme.palette.primary.main : "#9A9AAF",
|
|
|
|
display: "flex",
|
|
|
|
margin: isMobile ? 0 : undefined,
|
|
|
|
"& .MuiFormControlLabel-label": {
|
2024-02-11 15:35:45 +00:00
|
|
|
wordBreak: "break-word",
|
|
|
|
height: variant.answer.length <= 60 ? undefined : "60px",
|
|
|
|
overflow: "auto",
|
|
|
|
paddingLeft: "45px",
|
2024-02-15 08:43:02 +00:00
|
|
|
"&::-webkit-scrollbar": {
|
|
|
|
width: "4px",
|
|
|
|
},
|
|
|
|
"&::-webkit-scrollbar-thumb": {
|
|
|
|
backgroundColor: "#b8babf",
|
|
|
|
}
|
2024-02-02 12:46:38 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
value={index}
|
|
|
|
onClick={async (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await sendAnswer({
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
body: `${currentQuestion.content.variants[index].answer} <img style="width:100%; max-width:250px; max-height:250px" src="${currentQuestion.content.variants[index].extendedText}"/>`,
|
2024-02-14 11:03:35 +00:00
|
|
|
qid: quizId,
|
2024-02-02 12:46:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
updateAnswer(
|
|
|
|
currentQuestion.id,
|
2024-02-11 18:04:30 +00:00
|
|
|
currentQuestion.content.variants[index].id,
|
|
|
|
currentQuestion.content.variants[index].points || 0
|
2024-02-02 12:46:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
enqueueSnackbar("ответ не был засчитан");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (answer === currentQuestion.content.variants[index].id) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
await sendAnswer({
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
body: "",
|
2024-02-14 11:03:35 +00:00
|
|
|
qid: quizId,
|
2024-02-02 12:46:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
enqueueSnackbar("ответ не был засчитан");
|
|
|
|
}
|
|
|
|
deleteAnswer(currentQuestion.id);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
control={
|
|
|
|
<Radio checkedIcon={<RadioCheck color={theme.palette.primary.main} />} icon={<RadioIcon />} />
|
|
|
|
}
|
|
|
|
label={variant.answer}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Box>
|
|
|
|
</RadioGroup>
|
|
|
|
{/* {(variant?.extendedText || currentQuestion.content.back) && ( */}
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
maxWidth: "450px",
|
|
|
|
width: "100%",
|
|
|
|
height: "450px",
|
|
|
|
border: "1px solid #9A9AAF",
|
|
|
|
borderRadius: "12px",
|
|
|
|
overflow: "hidden",
|
|
|
|
display: "flex",
|
|
|
|
alignItems: "center",
|
|
|
|
justifyContent: "center",
|
|
|
|
backgroundColor: "#9A9AAF12",
|
2024-02-13 20:12:51 +00:00
|
|
|
color: "#9A9AAF",
|
|
|
|
textAlign: "center"
|
2024-02-02 12:46:38 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{answer ? (
|
|
|
|
variant?.extendedText ? (
|
|
|
|
<img
|
|
|
|
src={variant?.extendedText}
|
|
|
|
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<BlankImage />
|
|
|
|
)
|
2024-02-14 10:25:19 +00:00
|
|
|
) : currentQuestion.content.back !== " "
|
|
|
|
&& currentQuestion.content.back !== null
|
|
|
|
&& currentQuestion.content.back.length > 0
|
|
|
|
? (
|
2024-02-11 15:35:45 +00:00
|
|
|
<img
|
|
|
|
src={currentQuestion.content.back}
|
|
|
|
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
|
|
|
alt=""
|
|
|
|
/>
|
2024-02-02 12:46:38 +00:00
|
|
|
) : (currentQuestion.content.replText !== " " && currentQuestion.content.replText.length > 0) ? currentQuestion.content.replText : variant?.extendedText || isMobile ? (
|
|
|
|
"Выберите вариант ответа ниже"
|
|
|
|
) : (
|
|
|
|
"Выберите вариант ответа слева"
|
|
|
|
)}
|
|
|
|
|
|
|
|
</Box>
|
|
|
|
{/* )} */}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
2023-12-29 00:58:19 +00:00
|
|
|
|
2024-01-19 11:46:17 +00:00
|
|
|
};
|