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

116 lines
3.3 KiB
TypeScript
Raw Normal View History

2023-11-30 17:39:57 +00:00
import {
2023-12-11 13:07:41 +00:00
Box,
Typography,
RadioGroup,
FormControlLabel,
Radio,
useTheme,
useMediaQuery,
2023-11-30 17:39:57 +00:00
} from "@mui/material";
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 { QuizQuestionImages } from "../../../model/questionTypes/images";
type ImagesProps = {
currentQuestion: QuizQuestionImages;
2023-11-30 17:39:57 +00:00
};
export const Images = ({ currentQuestion }: ImagesProps) => {
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
) ?? {};
2023-11-30 17:39:57 +00:00
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
const isMobile = useMediaQuery(theme.breakpoints.down(500));
return (
<Box>
<Typography variant="h5">{currentQuestion.title}</Typography>
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",
marginTop: "20px",
}}
>
<Box
sx={{
display: "grid",
gap: "15px",
gridTemplateColumns: isTablet
? isMobile
? "repeat(1, 1fr)"
: "repeat(2, 1fr)"
: "repeat(3, 1fr)",
width: "100%",
}}
>
2023-12-11 14:26:17 +00:00
{currentQuestion.content.variants.map((variant, index) => (
<Box
key={index}
sx={{
borderRadius: "5px",
border: `1px solid ${theme.palette.grey2.main}`,
}}
>
<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}
2023-11-30 17:39:57 +00:00
sx={{
2023-12-11 14:26:17 +00:00
display: "block",
textAlign: "center",
color: theme.palette.grey2.main,
marginTop: "10px",
2023-11-30 17:39:57 +00:00
}}
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
}
2023-12-11 14:26:17 +00:00
}}
value={index}
control={
<Radio checkedIcon={<RadioCheck />} icon={<RadioIcon />} />
}
label={variant.answer}
/>
</Box>
))}
2023-11-30 17:39:57 +00:00
</Box>
</RadioGroup>
</Box>
);
};