import { Box, Rating as RatingComponent, Typography, useTheme } from "@mui/material"; import { updateAnswer, useQuizViewStore } from "@stores/quizView"; import FlagIcon from "@icons/questionsPage/FlagIcon"; import StarIconMini from "@icons/questionsPage/StarIconMini"; import HashtagIcon from "@icons/questionsPage/hashtagIcon"; import HeartIcon from "@icons/questionsPage/heartIcon"; import LightbulbIcon from "@icons/questionsPage/lightbulbIcon"; import LikeIcon from "@icons/questionsPage/likeIcon"; import TropfyIcon from "@icons/questionsPage/tropfyIcon"; import { sendAnswer } from "@api/quizRelase"; import { enqueueSnackbar } from "notistack"; import { useRootContainerSize } from "../../../contexts/RootContainerWidthContext"; import type { QuizQuestionRating } from "../../../model/questionTypes/rating"; import { useQuizData } from "@contexts/QuizDataContext"; 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 { quizId } = useQuizData(); const { answers } = useQuizViewStore(); const theme = useTheme(); const isMobile = useRootContainerSize() < 650; const { answer } = answers.find( ({ questionId }) => questionId === currentQuestion.id ) ?? {}; const form = buttonRatingForm.find( ({ name }) => name === currentQuestion.content.form ); return ( {currentQuestion.title} { try { await sendAnswer({ questionId: currentQuestion.id, body: String(value) + " из " + currentQuestion.content.steps, qid: quizId, }); updateAnswer(currentQuestion.id, String(value), 0); } 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} ); };