2023-12-16 14:55:56 +00:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Typography,
|
|
|
|
RadioGroup,
|
|
|
|
FormControlLabel,
|
|
|
|
Radio,
|
|
|
|
useTheme,
|
|
|
|
FormControl,
|
|
|
|
} from "@mui/material";
|
|
|
|
|
2023-12-17 13:22:21 +00:00
|
|
|
import { useQuizViewStore, updateAnswer, deleteAnswer } from "@root/quizView/store";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
import RadioCheck from "@ui_kit/RadioCheck";
|
|
|
|
import RadioIcon from "@ui_kit/RadioIcon";
|
|
|
|
|
|
|
|
import type { QuizQuestionEmoji } from "../../../model/questionTypes/emoji";
|
2023-12-17 21:28:57 +00:00
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
import { sendAnswer } from "@api/quizRelase";
|
|
|
|
import { useQuestionsStore } from "@root/quizData/store"
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
type EmojiProps = {
|
|
|
|
currentQuestion: QuizQuestionEmoji;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
2023-12-17 21:28:57 +00:00
|
|
|
const { settings } = useQuestionsStore()
|
2023-12-16 14:55:56 +00:00
|
|
|
const { answers } = useQuizViewStore();
|
|
|
|
const theme = useTheme();
|
|
|
|
const { answer } =
|
|
|
|
answers.find(
|
2023-12-17 13:22:21 +00:00
|
|
|
({ questionId }) => questionId === currentQuestion.id
|
2023-12-16 14:55:56 +00:00
|
|
|
) ?? {};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
<Typography variant="h5">{currentQuestion.title}</Typography>
|
|
|
|
<RadioGroup
|
2023-12-17 13:22:21 +00:00
|
|
|
name={currentQuestion.id.toString()}
|
2023-12-16 14:55:56 +00:00
|
|
|
value={currentQuestion.content.variants.findIndex(
|
|
|
|
({ id }) => answer === id
|
|
|
|
)}
|
|
|
|
onChange={({ target }) =>
|
|
|
|
updateAnswer(
|
2023-12-17 13:22:21 +00:00
|
|
|
currentQuestion.id,
|
2023-12-16 14:55:56 +00:00
|
|
|
currentQuestion.content.variants[Number(target.value)].id
|
|
|
|
)
|
|
|
|
}
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexWrap: "wrap",
|
|
|
|
flexDirection: "row",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
marginTop: "20px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box sx={{ display: "flex", width: "100%", gap: "42px" }}>
|
|
|
|
{currentQuestion.content.variants.map((variant, index) => (
|
|
|
|
<FormControl
|
|
|
|
key={variant.id}
|
|
|
|
sx={{
|
|
|
|
borderRadius: "12px",
|
|
|
|
border: `1px solid ${theme.palette.grey2.main}`,
|
|
|
|
overflow: "hidden",
|
|
|
|
maxWidth: "317px",
|
|
|
|
width: "100%",
|
|
|
|
height: "255px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
alignItems: "center",
|
|
|
|
height: "193px",
|
|
|
|
background: "#ffffff",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
width: "100%",
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "center",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{variant.extendedText && (
|
|
|
|
<Typography fontSize={"100px"}>
|
|
|
|
{variant.extendedText}
|
|
|
|
</Typography>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<FormControlLabel
|
|
|
|
key={variant.id}
|
|
|
|
sx={{
|
|
|
|
margin: 0,
|
|
|
|
padding: "15px",
|
|
|
|
color: "#4D4D4D",
|
|
|
|
display: "flex",
|
|
|
|
gap: "10px",
|
|
|
|
}}
|
|
|
|
value={index}
|
2023-12-17 21:28:57 +00:00
|
|
|
onClick={async (event) => {
|
2023-12-16 14:55:56 +00:00
|
|
|
event.preventDefault();
|
|
|
|
|
2023-12-17 21:28:57 +00:00
|
|
|
try {
|
|
|
|
|
|
|
|
await sendAnswer({
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
body: currentQuestion.content.variants[index].id,
|
|
|
|
//@ts-ignore
|
|
|
|
qid: settings.qid
|
|
|
|
})
|
|
|
|
|
|
|
|
updateAnswer(
|
|
|
|
currentQuestion.id,
|
|
|
|
currentQuestion.content.variants[index].id
|
|
|
|
);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
enqueueSnackbar("ответ не был засчитан")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
if (answer === currentQuestion.content.variants[index].id) {
|
2023-12-17 13:22:21 +00:00
|
|
|
deleteAnswer(currentQuestion.id);
|
2023-12-16 14:55:56 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
control={
|
|
|
|
<Radio checkedIcon={<RadioCheck />} icon={<RadioIcon />} />
|
|
|
|
}
|
|
|
|
label={
|
|
|
|
<Box sx={{ display: "flex", gap: "10px" }}>
|
|
|
|
<Typography>{variant.answer}</Typography>
|
|
|
|
</Box>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</FormControl>
|
|
|
|
))}
|
|
|
|
</Box>
|
|
|
|
</RadioGroup>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|