2023-12-16 14:55:56 +00:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Typography,
|
|
|
|
Rating as RatingComponent,
|
|
|
|
useTheme,
|
2023-12-29 00:58:19 +00:00
|
|
|
useMediaQuery
|
2023-12-16 14:55:56 +00:00
|
|
|
} from "@mui/material";
|
|
|
|
|
2023-12-17 13:22:21 +00:00
|
|
|
import { useQuizViewStore, updateAnswer } from "@root/quizView/store";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
import TropfyIcon from "@icons/questionsPage/tropfyIcon";
|
|
|
|
import FlagIcon from "@icons/questionsPage/FlagIcon";
|
|
|
|
import HeartIcon from "@icons/questionsPage/heartIcon";
|
|
|
|
import LikeIcon from "@icons/questionsPage/likeIcon";
|
|
|
|
import LightbulbIcon from "@icons/questionsPage/lightbulbIcon";
|
|
|
|
import HashtagIcon from "@icons/questionsPage/hashtagIcon";
|
|
|
|
import StarIconMini from "@icons/questionsPage/StarIconMini";
|
|
|
|
|
|
|
|
import type { QuizQuestionRating } from "../../../model/questionTypes/rating";
|
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 RatingProps = {
|
|
|
|
currentQuestion: QuizQuestionRating;
|
|
|
|
};
|
|
|
|
|
|
|
|
const buttonRatingForm = [
|
|
|
|
{
|
|
|
|
name: "star",
|
|
|
|
icon: (color: string) => <StarIconMini width={50} color={color} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "trophie",
|
|
|
|
icon: (color: string) => <TropfyIcon color={color} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "flag",
|
|
|
|
icon: (color: string) => <FlagIcon color={color} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "heart",
|
|
|
|
icon: (color: string) => <HeartIcon color={color} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "like",
|
|
|
|
icon: (color: string) => <LikeIcon color={color} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "bubble",
|
|
|
|
icon: (color: string) => <LightbulbIcon color={color} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "hashtag",
|
|
|
|
icon: (color: string) => <HashtagIcon color={color} />,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export const Rating = ({ currentQuestion }: RatingProps) => {
|
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();
|
2023-12-29 00:58:19 +00:00
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(650));
|
2023-12-16 14:55:56 +00:00
|
|
|
const { answer } =
|
|
|
|
answers.find(
|
2023-12-17 13:22:21 +00:00
|
|
|
({ questionId }) => questionId === currentQuestion.id
|
2023-12-16 14:55:56 +00:00
|
|
|
) ?? {};
|
|
|
|
const form = buttonRatingForm.find(
|
|
|
|
({ name }) => name === currentQuestion.content.form
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Box>
|
2023-12-29 00:58:19 +00:00
|
|
|
<Typography variant="h5" color={theme.palette.text.primary}>{currentQuestion.title}</Typography>
|
2023-12-16 14:55:56 +00:00
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "inline-flex",
|
|
|
|
alignItems: "center",
|
|
|
|
gap: "20px",
|
|
|
|
marginTop: "20px",
|
2023-12-29 00:58:19 +00:00
|
|
|
width: isMobile ? "100%" : undefined
|
2023-12-16 14:55:56 +00:00
|
|
|
}}
|
|
|
|
>
|
2023-12-29 00:58:19 +00:00
|
|
|
<Typography sx={{
|
|
|
|
color: "#9A9AAF"
|
|
|
|
// color: theme.palette.grey2.main
|
|
|
|
}}>
|
2023-12-16 14:55:56 +00:00
|
|
|
{currentQuestion.content.ratingNegativeDescription}
|
|
|
|
</Typography>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "inline-block",
|
|
|
|
width: "100%",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<RatingComponent
|
|
|
|
value={Number(answer || 0)}
|
2023-12-17 21:28:57 +00:00
|
|
|
onChange={async (_, value) => {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2023-12-29 00:58:19 +00:00
|
|
|
|
2023-12-17 21:28:57 +00:00
|
|
|
await sendAnswer({
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
body: String(value),
|
|
|
|
//@ts-ignore
|
|
|
|
qid: settings.qid
|
|
|
|
})
|
2023-12-29 00:58:19 +00:00
|
|
|
|
2023-12-17 21:28:57 +00:00
|
|
|
updateAnswer(currentQuestion.id, String(value))
|
2023-12-29 00:58:19 +00:00
|
|
|
|
2023-12-17 21:28:57 +00:00
|
|
|
} catch (e) {
|
|
|
|
enqueueSnackbar("ответ не был засчитан")
|
|
|
|
}
|
2023-12-29 00:58:19 +00:00
|
|
|
}}
|
|
|
|
sx={{ height: "50px",
|
|
|
|
gap: isMobile ? undefined : "15px",
|
|
|
|
justifyContent: isMobile ? "space-between" : undefined,
|
|
|
|
width: isMobile ? "100%" : undefined
|
|
|
|
}}
|
2023-12-16 14:55:56 +00:00
|
|
|
max={currentQuestion.content.steps}
|
2023-12-29 00:58:19 +00:00
|
|
|
icon={form?.icon(theme.palette.primary.main)}
|
|
|
|
emptyIcon={form?.icon("#9A9AAF")}
|
2023-12-16 14:55:56 +00:00
|
|
|
/>
|
|
|
|
</Box>
|
2023-12-29 00:58:19 +00:00
|
|
|
<Typography sx={{ color: "#9A9AAF" }}>
|
2023-12-16 14:55:56 +00:00
|
|
|
{currentQuestion.content.ratingPositiveDescription}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
2023-12-29 00:58:19 +00:00
|
|
|
|
|
|
|
};
|