frontPanel/src/pages/Questions/RatingOptions/RatingOptions.tsx
2023-09-06 16:20:12 +03:00

88 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useState } from "react";
import { useParams } from "react-router-dom";
import { Box, Typography, useTheme } from "@mui/material";
import ButtonsOptions from "../ButtonsOptions";
import Rating from "@mui/material/Rating";
import RatingStar from "../../../assets/icons/questionsPage/ratingStar";
import SwitchRating from "./switchRating";
import { questionStore, updateQuestionsList } from "@root/questions";
interface Props {
totalIndex: number;
}
export default function RatingOptions({ totalIndex }: Props) {
const [switchState, setSwitchState] = useState("setting");
const quizId = Number(useParams().quizId);
const { listQuestions } = questionStore();
const theme = useTheme();
const SSHC = (data: string) => {
setSwitchState(data);
};
return (
<>
<Box
sx={{
width: "100%",
maxWidth: "310px",
display: "flex",
padding: "20px",
flexDirection: "column",
gap: "20px",
}}
>
<Rating
name="customized-color"
defaultValue={listQuestions[quizId][totalIndex].content.starts}
getLabelText={(value: number) =>
`${value} Heart${value !== 1 ? "s" : ""}`
}
precision={1}
icon={<RatingStar color={theme.palette.brightPurple.main} />}
emptyIcon={<RatingStar color={"#9A9AAF"} />}
sx={{ display: "flex", gap: "15px" }}
onChange={(_, value) => {
const clonContent = listQuestions[quizId][totalIndex].content;
clonContent.starts = value || 0;
updateQuestionsList(quizId, totalIndex, { content: clonContent });
}}
/>
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}}
>
<Typography
sx={{
color: theme.palette.grey2.main,
fontSize: "16px",
fontWeight: 400,
}}
>
Негативно
</Typography>
<Typography
sx={{
color: theme.palette.grey2.main,
fontSize: "16px",
fontWeight: 400,
}}
>
Позитивно
</Typography>
</Box>
</Box>
<ButtonsOptions
switchState={switchState}
SSHC={SSHC}
totalIndex={totalIndex}
/>
<SwitchRating switchState={switchState} totalIndex={totalIndex} />
</>
);
}