2023-12-16 14:55:56 +00:00
|
|
|
import {
|
2024-02-02 14:35:02 +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-05 10:10:02 +00:00
|
|
|
import { deleteAnswer, updateAnswer, useQuizViewStore } from "@stores/quizView/store";
|
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-05 10:10:02 +00:00
|
|
|
import { enqueueSnackbar } from "notistack";
|
2024-02-08 13:42:31 +00:00
|
|
|
import { useQuizId } from "../../../contexts/QuizIdContext";
|
2024-02-05 10:10:02 +00:00
|
|
|
import { useRootContainerSize } from "../../../contexts/RootContainerWidthContext";
|
|
|
|
import type { QuizQuestionImages } from "../../../model/questionTypes/images";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
type ImagesProps = {
|
2024-02-02 14:35:02 +00:00
|
|
|
currentQuestion: QuizQuestionImages;
|
2023-12-16 14:55:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const Images = ({ currentQuestion }: ImagesProps) => {
|
2024-02-08 13:42:31 +00:00
|
|
|
const qid = useQuizId();
|
2024-02-02 14:35:02 +00:00
|
|
|
const { answers } = useQuizViewStore();
|
|
|
|
const theme = useTheme();
|
2024-02-05 10:10:02 +00:00
|
|
|
const answer = answers.find(({ questionId }) => questionId === currentQuestion.id)?.answer;
|
|
|
|
const isTablet = useRootContainerSize() < 1000;
|
|
|
|
const isMobile = useRootContainerSize() < 500;
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
<Typography variant="h5" color={theme.palette.text.primary}>{currentQuestion.title}</Typography>
|
|
|
|
<RadioGroup
|
|
|
|
name={currentQuestion.id}
|
|
|
|
value={currentQuestion.content.variants.findIndex(
|
|
|
|
({ id }) => answer === id
|
|
|
|
)}
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexWrap: "wrap",
|
|
|
|
flexDirection: "row",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
marginTop: "20px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "grid",
|
|
|
|
gap: "15px",
|
|
|
|
gridTemplateColumns: isTablet
|
|
|
|
? isMobile
|
|
|
|
? "repeat(1, 1fr)"
|
|
|
|
: "repeat(2, 1fr)"
|
|
|
|
: "repeat(3, 1fr)",
|
|
|
|
width: "100%",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{currentQuestion.content.variants.map((variant, index) => (
|
|
|
|
<Box
|
|
|
|
key={index}
|
|
|
|
sx={{
|
|
|
|
cursor: "pointer",
|
|
|
|
borderRadius: "5px",
|
|
|
|
border: `1px solid`,
|
|
|
|
borderColor: answer === variant.id ? theme.palette.primary.main : "#9A9AAF",
|
|
|
|
}}
|
|
|
|
onClick={async (event) => {
|
|
|
|
event.preventDefault();
|
2023-12-29 17:17:50 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
try {
|
2023-12-29 17:17:50 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
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-08 13:42:31 +00:00
|
|
|
qid,
|
2024-02-02 14:35:02 +00:00
|
|
|
});
|
2023-12-29 17:17:50 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
updateAnswer(
|
|
|
|
currentQuestion.id,
|
|
|
|
currentQuestion.content.variants[index].id
|
|
|
|
);
|
2023-12-29 17:17:50 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
} catch (e) {
|
|
|
|
enqueueSnackbar("ответ не был засчитан");
|
|
|
|
}
|
2023-12-29 17:17:50 +00:00
|
|
|
|
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
if (answer === currentQuestion.content.variants[index].id) {
|
|
|
|
deleteAnswer(currentQuestion.id);
|
|
|
|
try {
|
2023-12-29 17:17:50 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
await sendAnswer({
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
body: "",
|
2024-02-08 13:42:31 +00:00
|
|
|
qid,
|
2024-02-02 14:35:02 +00:00
|
|
|
});
|
2023-12-29 17:17:50 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
} catch (e) {
|
|
|
|
enqueueSnackbar("ответ не был засчитан");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
|
|
|
<Box sx={{ width: "100%", height: "300px" }}>
|
|
|
|
{variant.extendedText && (
|
|
|
|
<img
|
|
|
|
src={variant.extendedText}
|
|
|
|
alt=""
|
|
|
|
style={{
|
|
|
|
display: "block",
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
objectFit: "cover",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<FormControlLabel
|
|
|
|
key={variant.id}
|
|
|
|
sx={{
|
|
|
|
textAlign: "center",
|
|
|
|
color: theme.palette.text.primary,
|
|
|
|
marginTop: "10px",
|
|
|
|
marginLeft: 0,
|
|
|
|
padding: "10px",
|
|
|
|
"& .MuiFormControlLabel-label": {
|
|
|
|
wordBreak: "break-word",
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
value={index}
|
|
|
|
control={
|
|
|
|
<Radio checkedIcon={<RadioCheck color={theme.palette.primary.main} />} icon={<RadioIcon />} />
|
|
|
|
}
|
|
|
|
label={variant.answer}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
))}
|
2023-12-16 14:55:56 +00:00
|
|
|
</Box>
|
2024-02-02 14:35:02 +00:00
|
|
|
</RadioGroup>
|
2023-12-16 14:55:56 +00:00
|
|
|
</Box>
|
2024-02-02 14:35:02 +00:00
|
|
|
);
|
2023-12-29 00:58:19 +00:00
|
|
|
|
2024-01-19 11:46:17 +00:00
|
|
|
};
|