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

133 lines
4.2 KiB
TypeScript
Raw Normal View History

2023-11-30 17:39:57 +00:00
import {
Box,
Typography,
RadioGroup,
FormControlLabel,
Radio,
useTheme, useMediaQuery,
2023-11-30 17:39:57 +00:00
} from "@mui/material";
import gag from "./gag.png"
2023-12-11 14:26:17 +00:00
import { useQuizViewStore, updateAnswer, deleteAnswer } 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";
import {modes} from "../../../utils/themes/Publication/themePublication";
import {useCurrentQuiz} from "@root/quizes/hooks";
2023-11-30 17:39:57 +00:00
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();
const mode = modes;
const quiz = useCurrentQuiz();
2023-11-30 17:39:57 +00:00
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(650));
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" color={theme.palette.text.primary}>{currentQuestion.title}</Typography>
<Box sx={{
display: "flex",
marginTop: "20px",
flexDirection: isMobile ? "column-reverse" : undefined,
gap: isMobile ? "30px" : undefined
}}>
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-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%", gap: isMobile ? "20px" : undefined }}>
2023-12-11 14:26:17 +00:00
{currentQuestion.content.variants.map((variant, index) => (
2023-11-30 17:39:57 +00:00
<FormControlLabel
2023-12-11 14:26:17 +00:00
key={variant.id}
2023-11-30 17:39:57 +00:00
sx={{
marginBottom: "15px",
borderRadius: "5px",
padding: "15px",
color: theme.palette.text.primary,
backgroundColor: mode[quiz.config.theme] ? "white" : theme.palette.background.default,
border: `1px solid`,
borderColor: answer === variant.id ? theme.palette.primary.main : "#9A9AAF",
2023-11-30 17:39:57 +00:00
display: "flex",
margin: isMobile ? 0 : undefined,
2023-11-30 17:39:57 +00:00
}}
value={index}
2023-12-11 14:26:17 +00:00
onClick={(event) => {
event.preventDefault();
updateAnswer(
currentQuestion.content.id,
currentQuestion.content.variants[index].id
);
if (answer === currentQuestion.content.variants[index].id) {
deleteAnswer(currentQuestion.content.id);
}
}}
2023-11-30 17:39:57 +00:00
control={
<Radio checkedIcon={<RadioCheck color={theme.palette.primary.main}/>} icon={<RadioIcon />} />
2023-11-30 17:39:57 +00:00
}
2023-12-11 14:26:17 +00:00
label={variant.answer}
2023-11-30 17:39:57 +00:00
/>
))}
</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 #9A9AAF",
2023-12-11 13:07:41 +00:00
borderRadius: "12px",
overflow: "hidden",
display: "flex",
alignItems: "center",
justifyContent: "center",
backgroundColor: "#9A9AAF12",
color: "#9A9AAF"
2023-12-11 13:07:41 +00:00
}}
>
{
answer ?
<img
2023-12-11 13:07:41 +00:00
src={
variant?.extendedText || gag
2023-12-11 13:07:41 +00:00
}
2023-11-30 17:39:57 +00:00
style={{ width: "100%", height: "100%", objectFit: "cover" }}
alt=""
/>
:
(variant?.extendedText || isMobile ? ("Выберите вариант ответа ниже") : ("Выберите вариант ответа слева"))
}
2023-11-30 17:39:57 +00:00
</Box>
{/* )} */}
2023-11-30 17:39:57 +00:00
</Box>
</Box>
);
};