2023-12-16 14:55:56 +00:00
|
|
|
import {
|
2024-02-02 14:35:02 +00:00
|
|
|
Box,
|
|
|
|
Rating as RatingComponent,
|
2024-02-05 10:10:02 +00:00
|
|
|
Typography,
|
|
|
|
useTheme
|
2023-12-16 14:55:56 +00:00
|
|
|
} from "@mui/material";
|
|
|
|
|
2024-02-05 10:10:02 +00:00
|
|
|
import { updateAnswer, useQuizViewStore } from "@stores/quizView/store";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
import FlagIcon from "@icons/questionsPage/FlagIcon";
|
2024-02-05 10:10:02 +00:00
|
|
|
import StarIconMini from "@icons/questionsPage/StarIconMini";
|
|
|
|
import HashtagIcon from "@icons/questionsPage/hashtagIcon";
|
2023-12-16 14:55:56 +00:00
|
|
|
import HeartIcon from "@icons/questionsPage/heartIcon";
|
|
|
|
import LightbulbIcon from "@icons/questionsPage/lightbulbIcon";
|
2024-02-05 10:10:02 +00:00
|
|
|
import LikeIcon from "@icons/questionsPage/likeIcon";
|
|
|
|
import TropfyIcon from "@icons/questionsPage/tropfyIcon";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2023-12-17 21:28:57 +00:00
|
|
|
import { sendAnswer } from "@api/quizRelase";
|
2024-02-05 10:10:02 +00:00
|
|
|
import { enqueueSnackbar } from "notistack";
|
2024-02-08 13:42:31 +00:00
|
|
|
import { useQuizId } from "../../../contexts/QuizIdContext";
|
2024-02-05 10:10:02 +00:00
|
|
|
import { useRootContainerSize } from "../../../contexts/RootContainerWidthContext";
|
|
|
|
import type { QuizQuestionRating } from "../../../model/questionTypes/rating";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
type RatingProps = {
|
2024-02-02 14:35:02 +00:00
|
|
|
currentQuestion: QuizQuestionRating;
|
2023-12-16 14:55:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const buttonRatingForm = [
|
2024-02-02 14:35:02 +00:00
|
|
|
{
|
|
|
|
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} />,
|
|
|
|
},
|
2023-12-16 14:55:56 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
export const Rating = ({ currentQuestion }: RatingProps) => {
|
2024-02-08 13:42:31 +00:00
|
|
|
const qid = useQuizId();
|
2024-02-02 14:35:02 +00:00
|
|
|
const { answers } = useQuizViewStore();
|
|
|
|
const theme = useTheme();
|
2024-02-05 10:10:02 +00:00
|
|
|
const isMobile = useRootContainerSize() < 650;
|
2024-02-02 14:35:02 +00:00
|
|
|
const { answer } =
|
|
|
|
answers.find(
|
|
|
|
({ questionId }) => questionId === currentQuestion.id
|
|
|
|
) ?? {};
|
|
|
|
const form = buttonRatingForm.find(
|
|
|
|
({ name }) => name === currentQuestion.content.form
|
|
|
|
);
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
<Typography variant="h5" color={theme.palette.text.primary}>{currentQuestion.title}</Typography>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "inline-flex",
|
|
|
|
alignItems: "center",
|
|
|
|
gap: "20px",
|
|
|
|
marginTop: "20px",
|
|
|
|
flexDirection: "column",
|
|
|
|
width: isMobile ? "100%" : undefined,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "inline-block",
|
|
|
|
width: "100%",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<RatingComponent
|
|
|
|
value={Number(answer || 0)}
|
|
|
|
onChange={async (_, value) => {
|
2024-01-30 16:49:33 +00:00
|
|
|
|
2023-12-17 21:28:57 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
try {
|
2023-12-17 21:28:57 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
await sendAnswer({
|
|
|
|
questionId: currentQuestion.id,
|
|
|
|
body: String(value) + " из " + currentQuestion.content.steps,
|
2024-02-08 13:42:31 +00:00
|
|
|
qid,
|
2024-02-02 14:35:02 +00:00
|
|
|
});
|
2024-01-05 17:00:30 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
updateAnswer(currentQuestion.id, String(value));
|
2024-01-05 17:00:30 +00:00
|
|
|
|
2024-02-02 14:35:02 +00:00
|
|
|
} 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")}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
gap: 2,
|
|
|
|
width: "100%",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Typography sx={{
|
|
|
|
color: "#9A9AAF"
|
|
|
|
// color: theme.palette.grey2.main
|
|
|
|
}}>
|
|
|
|
{currentQuestion.content.ratingNegativeDescription}
|
|
|
|
</Typography>
|
|
|
|
<Typography sx={{ color: "#9A9AAF" }}>
|
|
|
|
{currentQuestion.content.ratingPositiveDescription}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
2024-01-05 17:00:30 +00:00
|
|
|
</Box>
|
2024-02-02 14:35:02 +00:00
|
|
|
);
|
2023-12-29 00:58:19 +00:00
|
|
|
|
2024-01-19 11:46:17 +00:00
|
|
|
};
|