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

69 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-11-30 17:39:57 +00:00
import {
Box,
Typography,
Rating as RatingComponent,
useTheme,
} from "@mui/material";
2023-12-01 13:48:25 +00:00
import { useQuizViewStore, updateAnswer } from "@root/quizView";
2023-11-30 17:39:57 +00:00
import StarIconMini from "@icons/questionsPage/StarIconMini";
import type { QuizQuestionRating } from "../../../model/questionTypes/rating";
type RatingProps = {
currentQuestion: QuizQuestionRating;
2023-11-30 17:39:57 +00:00
};
export const Rating = ({ currentQuestion }: RatingProps) => {
2023-12-01 13:48:25 +00:00
const { answers } = useQuizViewStore();
2023-11-30 17:39:57 +00:00
const theme = useTheme();
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",
}}
>
<RatingComponent
2023-12-01 13:48:25 +00:00
value={Number(answer || 0)}
onChange={(_, value) => updateAnswer(currentQuestion.content.id, String(value))}
2023-11-30 17:39:57 +00:00
sx={{ height: "50px" }}
max={currentQuestion.content.steps}
2023-11-30 17:39:57 +00:00
icon={
<StarIconMini
color={theme.palette.brightPurple.main}
width={50}
sx={{ transform: "scale(0.8)" }}
/>
}
emptyIcon={
<StarIconMini
color={theme.palette.grey2.main}
width={50}
sx={{ transform: "scale(0.8)" }}
/>
}
/>
<Box
sx={{
display: "flex",
justifyContent: "space-between",
maxWidth: `${currentQuestion.content.steps * 50}px`,
2023-11-30 17:39:57 +00:00
color: theme.palette.grey2.main,
}}
>
<Typography>{currentQuestion.content.ratingNegativeDescription}</Typography>
<Typography>{currentQuestion.content.ratingPositiveDescription}</Typography>
2023-11-30 17:39:57 +00:00
</Box>
</Box>
</Box>
);
};