import { Box, Typography, Rating as RatingComponent, useTheme, useMediaQuery } from "@mui/material"; import { useQuizViewStore, updateAnswer } from "@stores/quizView/store"; 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"; import { enqueueSnackbar } from "notistack"; import { sendAnswer } from "@api/quizRelase"; import { useQuestionsStore } from "@stores/quizData/store"; type RatingProps = { currentQuestion: QuizQuestionRating; }; const buttonRatingForm = [ { name: "star", icon: (color: string) => , }, { name: "trophie", icon: (color: string) => , }, { name: "flag", icon: (color: string) => , }, { name: "heart", icon: (color: string) => , }, { name: "like", icon: (color: string) => , }, { name: "bubble", icon: (color: string) => , }, { name: "hashtag", icon: (color: string) => , }, ]; export const Rating = ({ currentQuestion }: RatingProps) => { const { settings } = useQuestionsStore() const { answers } = useQuizViewStore(); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down(650)); const { answer } = answers.find( ({ questionId }) => questionId === currentQuestion.id ) ?? {}; const form = buttonRatingForm.find( ({ name }) => name === currentQuestion.content.form ); if (!settings) throw new Error("settings is null"); return ( {currentQuestion.title} { try { await sendAnswer({ questionId: currentQuestion.id, body: String(value) + " из " + currentQuestion.content.steps, qid: settings.qid }) updateAnswer(currentQuestion.id, String(value)) } catch (e) { enqueueSnackbar("ответ не был засчитан") } }} sx={{ height: "50px", gap: isMobile ? undefined : "15px", justifyContent: isMobile ? "space-between" : undefined, width: isMobile ? "100%" : undefined }} max={currentQuestion.content.steps} icon={form?.icon(theme.palette.primary.main)} emptyIcon={form?.icon("#9A9AAF")} /> {currentQuestion.content.ratingNegativeDescription} {currentQuestion.content.ratingPositiveDescription} ); };