frontPanel/src/pages/Questions/RatingOptions/RatingOptions.tsx

142 lines
4.2 KiB
TypeScript
Raw Normal View History

2023-09-06 06:47:23 +00:00
import { useState } from "react";
2023-09-06 13:20:12 +00:00
import { useParams } from "react-router-dom";
2023-08-24 11:09:47 +00:00
import { Box, Typography, useTheme } from "@mui/material";
import ButtonsOptions from "../ButtonsOptions";
import RatingStar from "../../../assets/icons/questionsPage/ratingStar";
import SwitchRating from "./switchRating";
2023-09-06 06:47:23 +00:00
import { questionStore, updateQuestionsList } from "@root/questions";
2023-09-12 09:56:15 +00:00
import CustomTextField from "@ui_kit/CustomTextField";
2023-08-24 11:09:47 +00:00
interface Props {
totalIndex: number;
}
2023-08-24 11:09:47 +00:00
export default function RatingOptions({ totalIndex }: Props) {
2023-09-06 06:47:23 +00:00
const [switchState, setSwitchState] = useState("setting");
2023-09-06 13:20:12 +00:00
const quizId = Number(useParams().quizId);
2023-09-06 06:47:23 +00:00
const { listQuestions } = questionStore();
2023-08-24 11:09:47 +00:00
const theme = useTheme();
2023-09-06 06:47:23 +00:00
2023-08-24 11:09:47 +00:00
const SSHC = (data: string) => {
setSwitchState(data);
};
2023-09-06 06:47:23 +00:00
2023-08-24 11:09:47 +00:00
return (
<>
<Box
sx={{
width: "100%",
maxWidth: "310px",
display: "flex",
padding: "20px",
flexDirection: "column",
gap: "20px",
}}
>
2023-09-12 09:56:15 +00:00
<Box sx={{ display: "flex", gap: "15px" }}>
<RatingStar
onClick={() => {
updateQuestionsList(quizId, totalIndex, {
content: {
...listQuestions[quizId][totalIndex].content,
ratingExpanded: true,
},
});
}}
sx={{
cursor: "pointer",
":hover": {
transform: "scale(1.1)",
transition: "0.2s",
},
}}
/>
<RatingStar />
<RatingStar />
<RatingStar />
<RatingStar
onClick={() => {
updateQuestionsList(quizId, totalIndex, {
content: {
...listQuestions[quizId][totalIndex].content,
ratingExpanded: true,
},
});
}}
sx={{
cursor: "pointer",
":hover": {
transform: "scale(1.1)",
transition: "0.2s",
},
}}
/>
</Box>
2023-08-24 11:09:47 +00:00
<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>
2023-09-12 09:56:15 +00:00
{listQuestions[quizId][totalIndex].content.ratingExpanded &&
(listQuestions[quizId][totalIndex].content.ratingDescription ? (
<Typography>
{listQuestions[quizId][totalIndex].content.ratingDescription}
</Typography>
) : (
<CustomTextField
placeholder={"Описание"}
text={listQuestions[quizId][totalIndex].content.ratingDescription}
onKeyDown={({ target, key }) => {
if (key === "Enter") {
const currentTarget = target as HTMLInputElement;
updateQuestionsList(quizId, totalIndex, {
content: {
...listQuestions[quizId][totalIndex].content,
ratingDescription: currentTarget.value.substring(0, 20),
},
});
}
}}
onBlur={({ target }) => {
updateQuestionsList(quizId, totalIndex, {
content: {
...listQuestions[quizId][totalIndex].content,
ratingDescription: target.value.substring(0, 20),
},
});
}}
/>
))}
2023-08-24 11:09:47 +00:00
</Box>
<ButtonsOptions
switchState={switchState}
SSHC={SSHC}
totalIndex={totalIndex}
/>
<SwitchRating switchState={switchState} totalIndex={totalIndex} />
</>
);
}