frontPanel/src/pages/ViewPublicationPage/questions/Varimg.tsx

100 lines
2.8 KiB
TypeScript
Raw Normal View History

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 = {
currentQuestion: QuizQuestionVarImg;
2023-11-30 17:39:57 +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>
<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
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(
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%" }}>
{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",
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>
{(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>
);
};