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

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-11-30 17:39:57 +00:00
import { Box, Typography } from "@mui/material";
import { Select as SelectComponent } from "../../../pages/Questions/Select";
2023-12-01 13:48:25 +00:00
import { useQuizViewStore, updateAnswer } from "@root/quizView";
2023-11-30 17:39:57 +00:00
import type { QuizQuestionSelect } from "../../../model/questionTypes/select";
type SelectProps = {
currentQuestion: QuizQuestionSelect;
2023-11-30 17:39:57 +00:00
};
export const Select = ({ currentQuestion }: SelectProps) => {
2023-12-01 13:48:25 +00:00
const { answers } = useQuizViewStore();
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
return (
<Box>
<Typography variant="h5">{currentQuestion.title}</Typography>
2023-11-30 17:39:57 +00:00
<Box
sx={{
display: "flex",
flexDirection: "column",
width: "100%",
marginTop: "20px",
}}
>
<SelectComponent
2023-12-11 13:07:41 +00:00
activeItemIndex={answer ? Number(answer) : -1}
items={currentQuestion.content.variants.map(({ answer }) => answer)}
2023-12-01 13:48:25 +00:00
onChange={(_, value) => {
updateAnswer(currentQuestion.content.id, String(value));
2023-11-30 17:39:57 +00:00
}}
/>
</Box>
</Box>
);
};