2023-11-30 17:39:57 +00:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Typography,
|
|
|
|
RadioGroup,
|
|
|
|
FormControlLabel,
|
|
|
|
Radio,
|
|
|
|
useTheme,
|
|
|
|
} from "@mui/material";
|
|
|
|
|
2023-12-01 13:48:25 +00:00
|
|
|
import { useQuizViewStore, updateAnswer } from "@root/quizView";
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
|
|
import RadioCheck from "@ui_kit/RadioCheck";
|
|
|
|
import RadioIcon from "@ui_kit/RadioIcon";
|
|
|
|
|
|
|
|
import type { QuizQuestionVarImg } from "../../../model/questionTypes/varimg";
|
|
|
|
|
|
|
|
type VarimgProps = {
|
2023-12-03 10:48:00 +00:00
|
|
|
currentQuestion: QuizQuestionVarImg;
|
2023-11-30 17:39:57 +00:00
|
|
|
};
|
|
|
|
|
2023-12-03 10:48:00 +00:00
|
|
|
export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
2023-12-01 13:48:25 +00:00
|
|
|
const { answers } = useQuizViewStore();
|
2023-11-30 17:39:57 +00:00
|
|
|
const theme = useTheme();
|
2023-12-11 13:07:41 +00:00
|
|
|
const { answer } =
|
|
|
|
answers.find(
|
|
|
|
({ questionId }) => questionId === currentQuestion.content.id
|
|
|
|
) ?? {};
|
|
|
|
const variant = currentQuestion.content.variants.find(
|
|
|
|
({ id }) => answer === id
|
|
|
|
);
|
2023-11-30 17:39:57 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Box>
|
2023-12-03 10:48:00 +00:00
|
|
|
<Typography variant="h5">{currentQuestion.title}</Typography>
|
2023-12-11 13:07:41 +00:00
|
|
|
<Box sx={{ display: "flex", marginTop: "20px" }}>
|
2023-11-30 17:39:57 +00:00
|
|
|
<RadioGroup
|
2023-12-03 10:48:00 +00:00
|
|
|
name={currentQuestion.id}
|
2023-12-11 13:07:41 +00:00
|
|
|
value={currentQuestion.content.variants.findIndex(
|
|
|
|
({ id }) => answer === id
|
|
|
|
)}
|
2023-12-01 13:48:25 +00:00
|
|
|
onChange={({ target }) =>
|
|
|
|
updateAnswer(
|
2023-12-03 10:48:00 +00:00
|
|
|
currentQuestion.content.id,
|
|
|
|
currentQuestion.content.variants[Number(target.value)].id
|
2023-12-01 13:48:25 +00:00
|
|
|
)
|
|
|
|
}
|
2023-11-30 17:39:57 +00:00
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexWrap: "wrap",
|
|
|
|
flexDirection: "row",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
flexBasis: "100%",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box sx={{ display: "flex", flexDirection: "column", width: "100%" }}>
|
2023-12-03 10:48:00 +00:00
|
|
|
{currentQuestion.content.variants.map(({ id, answer }, index) => (
|
2023-11-30 17:39:57 +00:00
|
|
|
<FormControlLabel
|
|
|
|
key={id}
|
|
|
|
sx={{
|
|
|
|
marginBottom: "15px",
|
|
|
|
borderRadius: "5px",
|
|
|
|
padding: "15px",
|
2023-12-09 00:22:19 +00:00
|
|
|
color: "#4D4D4D",
|
2023-11-30 17:39:57 +00:00
|
|
|
border: `1px solid ${theme.palette.grey2.main}`,
|
|
|
|
display: "flex",
|
|
|
|
}}
|
|
|
|
value={index}
|
|
|
|
control={
|
|
|
|
<Radio checkedIcon={<RadioCheck />} icon={<RadioIcon />} />
|
|
|
|
}
|
|
|
|
label={answer}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Box>
|
|
|
|
</RadioGroup>
|
2023-12-03 10:48:00 +00:00
|
|
|
{(variant?.extendedText || currentQuestion.content.back) && (
|
2023-12-11 13:07:41 +00:00
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
maxWidth: "450px",
|
|
|
|
width: "100%",
|
|
|
|
height: "450px",
|
|
|
|
border: "1px solid #E3E3E3",
|
|
|
|
borderRadius: "12px",
|
|
|
|
overflow: "hidden",
|
|
|
|
}}
|
|
|
|
>
|
2023-11-30 17:39:57 +00:00
|
|
|
<img
|
2023-12-11 13:07:41 +00:00
|
|
|
src={
|
|
|
|
answer ? variant?.extendedText : currentQuestion.content.back
|
|
|
|
}
|
2023-11-30 17:39:57 +00:00
|
|
|
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|