2023-12-16 14:55:56 +00:00
|
|
|
import {
|
2024-01-30 16:49:33 +00:00
|
|
|
Box,
|
|
|
|
FormControl,
|
|
|
|
FormControlLabel,
|
|
|
|
Radio,
|
|
|
|
RadioGroup,
|
|
|
|
Typography,
|
|
|
|
useTheme
|
2023-12-16 14:55:56 +00:00
|
|
|
} from "@mui/material";
|
|
|
|
|
2024-02-12 10:58:51 +00:00
|
|
|
import { deleteAnswer, updateAnswer, useQuizViewStore } from "@stores/quizView";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
import RadioCheck from "@ui_kit/RadioCheck";
|
|
|
|
import RadioIcon from "@ui_kit/RadioIcon";
|
|
|
|
|
2023-12-17 21:28:57 +00:00
|
|
|
import { sendAnswer } from "@api/quizRelase";
|
2024-02-02 14:35:02 +00:00
|
|
|
|
2024-01-30 16:49:33 +00:00
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
import type { QuizQuestionEmoji } from "../../../model/questionTypes/emoji";
|
2024-02-14 11:03:35 +00:00
|
|
|
import { useQuizData } from "@contexts/QuizDataContext";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
type EmojiProps = {
|
2024-02-02 14:35:02 +00:00
|
|
|
currentQuestion: QuizQuestionEmoji;
|
2023-12-16 14:55:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
2024-02-02 14:35:02 +00:00
|
|
|
const theme = useTheme();
|
2024-02-14 11:03:35 +00:00
|
|
|
const quizId = useQuizData();
|
2024-02-02 14:35:02 +00:00
|
|
|
const { answers } = useQuizViewStore();
|
|
|
|
const { answer } =
|
|
|
|
answers.find(
|
|
|
|
({ questionId }) => questionId === currentQuestion.id
|
|
|
|
) ?? {};
|
2024-01-30 16:49:33 +00:00
|
|
|
|
2023-12-29 00:58:19 +00:00
|
|
|
return (
|
2024-02-02 14:35:02 +00:00
|
|
|
<Box>
|
2024-02-15 01:20:35 +00:00
|
|
|
<Typography variant="h5" color={theme.palette.text.primary} sx={{wordBreak: "break-word"}}>{currentQuestion.title}</Typography>
|
2024-02-02 14:35:02 +00:00
|
|
|
<RadioGroup
|
|
|
|
name={currentQuestion.id}
|
|
|
|
value={currentQuestion.content.variants.findIndex(
|
|
|
|
({ id }) => answer === id
|
|
|
|
)}
|
|
|
|
onChange={({ target }) => {
|
|
|
|
updateAnswer(
|
|
|
|
currentQuestion.id,
|
2024-02-11 18:04:30 +00:00
|
|
|
currentQuestion.content.variants[Number(target.value)].answer,
|
|
|
|
currentQuestion.content.variants[Number(target.value)].points || 0
|
2024-02-02 14:35:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-12-16 14:55:56 +00:00
|
|
|
sx={{
|
|
|
|
display: "flex",
|
2024-02-02 14:35:02 +00:00
|
|
|
flexWrap: "wrap",
|
|
|
|
flexDirection: "row",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
marginTop: "20px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box sx={{ display: "flex", width: "100%", gap: "42px", flexWrap: "wrap" }}>
|
|
|
|
{currentQuestion.content.variants.map((variant, index) => (
|
|
|
|
<FormControl
|
|
|
|
key={variant.id}
|
|
|
|
sx={{
|
|
|
|
borderRadius: "12px",
|
|
|
|
border: `1px solid`,
|
|
|
|
borderColor: answer === variant.id ? theme.palette.primary.main : "#9A9AAF",
|
|
|
|
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: theme.palette.text.primary,
|
|
|
|
display: "flex",
|
|
|
|
gap: "10px",
|
2024-02-13 22:45:27 +00:00
|
|
|
alignItems:
|
|
|
|
variant.answer.length <= 60 ? "center" : "flex-start",
|
|
|
|
position: "relative",
|
|
|
|
height: "80px",
|
|
|
|
"& .MuiFormControlLabel-label": {
|
|
|
|
wordBreak: "break-word",
|
|
|
|
height: variant.answer.length <= 60 ? undefined : "60px",
|
|
|
|
overflow: "auto",
|
|
|
|
paddingLeft: "45px",
|
|
|
|
},
|
2024-02-02 14:35:02 +00:00
|
|
|
}}
|
|
|
|
value={index}
|
|
|
|
onClick={async (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await sendAnswer({
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
body: currentQuestion.content.variants[index].extendedText + " " + currentQuestion.content.variants[index].answer,
|
2024-02-14 11:03:35 +00:00
|
|
|
qid: quizId,
|
2024-02-02 14:35:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
updateAnswer(
|
|
|
|
currentQuestion.id,
|
2024-02-11 18:04:30 +00:00
|
|
|
currentQuestion.content.variants[index].id,
|
|
|
|
currentQuestion.content.variants[index].points || 0
|
2024-02-02 14:35:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
enqueueSnackbar("ответ не был засчитан");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (answer === currentQuestion.content.variants[index].id) {
|
|
|
|
deleteAnswer(currentQuestion.id);
|
|
|
|
try {
|
|
|
|
|
|
|
|
await sendAnswer({
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
body: "",
|
2024-02-14 11:03:35 +00:00
|
|
|
qid: quizId,
|
2024-02-02 14:35:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
enqueueSnackbar("ответ не был засчитан");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
|
|
|
|
control={
|
|
|
|
<Radio checkedIcon={<RadioCheck color={theme.palette.primary.main} />} icon={<RadioIcon />} />
|
|
|
|
}
|
|
|
|
label={
|
|
|
|
<Box sx={{ display: "flex", gap: "10px" }}>
|
|
|
|
<Typography sx={{ wordBreak: "break-word" }}>{variant.answer}</Typography>
|
|
|
|
</Box>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</FormControl>
|
|
|
|
))}
|
2023-12-16 14:55:56 +00:00
|
|
|
</Box>
|
2024-02-02 14:35:02 +00:00
|
|
|
</RadioGroup>
|
|
|
|
</Box>
|
2023-12-29 00:58:19 +00:00
|
|
|
);
|
2024-02-02 14:35:02 +00:00
|
|
|
|
2024-01-19 11:46:17 +00:00
|
|
|
};
|