2024-06-29 09:32:16 +00:00
|
|
|
import type { QuizQuestionEmoji } from "@model/questionTypes/emoji";
|
2024-04-23 14:45:49 +00:00
|
|
|
import { Box, RadioGroup, Typography, useTheme } from "@mui/material";
|
|
|
|
import { useQuizViewStore } from "@stores/quizView";
|
2024-06-29 09:32:16 +00:00
|
|
|
import { polyfillCountryFlagEmojis } from "country-flag-emoji-polyfill";
|
2024-04-23 14:45:49 +00:00
|
|
|
import { EmojiVariant } from "./EmojiVariant";
|
|
|
|
|
|
|
|
polyfillCountryFlagEmojis();
|
|
|
|
|
|
|
|
type EmojiProps = {
|
|
|
|
currentQuestion: QuizQuestionEmoji;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
|
|
|
const answers = useQuizViewStore((state) => state.answers);
|
|
|
|
const { updateAnswer } = useQuizViewStore((state) => state);
|
|
|
|
const theme = useTheme();
|
2024-05-31 16:41:18 +00:00
|
|
|
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
2024-04-23 14:45:49 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Box>
|
2024-06-29 09:32:16 +00:00
|
|
|
<Typography
|
|
|
|
variant="h5"
|
|
|
|
color={theme.palette.text.primary}
|
|
|
|
sx={{ wordBreak: "break-word" }}
|
|
|
|
>
|
2024-04-23 14:45:49 +00:00
|
|
|
{currentQuestion.title}
|
|
|
|
</Typography>
|
|
|
|
<RadioGroup
|
|
|
|
name={currentQuestion.id}
|
2024-05-31 16:41:18 +00:00
|
|
|
value={currentQuestion.content.variants.findIndex(({ id }) => answer === id)}
|
2024-04-23 14:45:49 +00:00
|
|
|
onChange={({ target }) =>
|
|
|
|
updateAnswer(
|
|
|
|
currentQuestion.id,
|
|
|
|
currentQuestion.content.variants[Number(target.value)].answer,
|
|
|
|
currentQuestion.content.variants[Number(target.value)].points || 0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexWrap: "wrap",
|
|
|
|
flexDirection: "row",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
marginTop: "20px",
|
|
|
|
}}
|
|
|
|
>
|
2024-05-31 16:41:18 +00:00
|
|
|
<Box sx={{ display: "flex", width: "100%", gap: "42px", flexWrap: "wrap" }}>
|
2024-04-23 14:45:49 +00:00
|
|
|
{currentQuestion.content.variants.map((variant, index) => (
|
|
|
|
<EmojiVariant
|
|
|
|
key={variant.id}
|
2024-06-29 09:32:16 +00:00
|
|
|
questionId={currentQuestion.id}
|
2024-04-23 14:45:49 +00:00
|
|
|
variant={variant}
|
|
|
|
index={index}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Box>
|
|
|
|
</RadioGroup>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|