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-09-15 12:37:12 +00:00
|
|
|
|
import { Box, Typography, useMediaQuery, useTheme } from "@mui/material";
|
2023-03-31 15:48:49 +00:00
|
|
|
|
import ButtonsOptions from "../ButtonsOptions";
|
|
|
|
|
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-03-31 15:48:49 +00:00
|
|
|
|
|
2023-09-18 07:45:14 +00:00
|
|
|
|
import TropfyIcon from "../../../assets/icons/questionsPage/tropfyIcon";
|
|
|
|
|
import FlagIcon from "../../../assets/icons/questionsPage/FlagIcon";
|
|
|
|
|
import HeartIcon from "../../../assets/icons/questionsPage/heartIcon";
|
|
|
|
|
import LikeIcon from "../../../assets/icons/questionsPage/likeIcon";
|
|
|
|
|
import LightbulbIcon from "../../../assets/icons/questionsPage/lightbulbIcon";
|
|
|
|
|
import HashtagIcon from "../../../assets/icons/questionsPage/hashtagIcon";
|
|
|
|
|
import StarIconMini from "../../../assets/icons/questionsPage/StarIconMini";
|
|
|
|
|
|
2023-08-24 11:09:47 +00:00
|
|
|
|
interface Props {
|
|
|
|
|
totalIndex: number;
|
2023-06-30 14:39:07 +00:00
|
|
|
|
}
|
2023-03-31 15:48:49 +00:00
|
|
|
|
|
2023-09-18 07:45:14 +00:00
|
|
|
|
export type ButtonRatingFrom = {
|
|
|
|
|
name: string;
|
|
|
|
|
icon: JSX.Element;
|
|
|
|
|
};
|
|
|
|
|
|
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-15 12:37:12 +00:00
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
2023-09-06 06:47:23 +00:00
|
|
|
|
|
2023-09-18 07:45:14 +00:00
|
|
|
|
const buttonRatingForm: ButtonRatingFrom[] = [
|
|
|
|
|
{ name: "star", icon: <StarIconMini color={theme.palette.grey2.main} /> },
|
|
|
|
|
{ name: "trophie", icon: <TropfyIcon color={theme.palette.grey2.main} /> },
|
|
|
|
|
{ name: "flag", icon: <FlagIcon color={theme.palette.grey2.main} /> },
|
|
|
|
|
{ name: "heart", icon: <HeartIcon color={theme.palette.grey2.main} /> },
|
|
|
|
|
{ name: "like", icon: <LikeIcon color={theme.palette.grey2.main} /> },
|
|
|
|
|
{
|
|
|
|
|
name: "bubble",
|
|
|
|
|
icon: <LightbulbIcon color={theme.palette.grey2.main} />,
|
|
|
|
|
},
|
|
|
|
|
{ name: "hashtag", icon: <HashtagIcon color={theme.palette.grey2.main} /> },
|
|
|
|
|
];
|
|
|
|
|
|
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={{
|
2023-09-15 12:37:12 +00:00
|
|
|
|
width: isMobile ? "auto" : "100%",
|
2023-08-24 11:09:47 +00:00
|
|
|
|
maxWidth: "310px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
padding: "20px",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
gap: "20px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-09-21 07:00:08 +00:00
|
|
|
|
<Box sx={{ display: "flex", gap: isMobile ? "10px" : "15px" }}>
|
2023-09-18 07:45:14 +00:00
|
|
|
|
{Array.from(
|
|
|
|
|
{ length: listQuestions[quizId][totalIndex].content.steps },
|
|
|
|
|
(_, index) => index
|
|
|
|
|
).map((itemNumber) => (
|
|
|
|
|
<Box
|
|
|
|
|
{...(itemNumber === 0 ||
|
|
|
|
|
itemNumber === listQuestions[quizId][totalIndex].content.steps - 1
|
|
|
|
|
? {
|
|
|
|
|
onClick: () => {
|
|
|
|
|
updateQuestionsList(quizId, totalIndex, {
|
|
|
|
|
content: {
|
|
|
|
|
...listQuestions[quizId][totalIndex].content,
|
|
|
|
|
ratingExpanded: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
sx: {
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
transform: "scale(1.5)",
|
|
|
|
|
":hover": {
|
|
|
|
|
transform: "scale(1.7)",
|
|
|
|
|
transition: "0.2s",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: { sx: { transform: "scale(1.5)" } })}
|
|
|
|
|
>
|
|
|
|
|
{
|
|
|
|
|
buttonRatingForm.find(
|
|
|
|
|
({ name }) =>
|
|
|
|
|
listQuestions[quizId][totalIndex].content.form === name
|
|
|
|
|
)?.icon
|
|
|
|
|
}
|
|
|
|
|
</Box>
|
|
|
|
|
))}
|
2023-09-12 09:56:15 +00:00
|
|
|
|
</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 ? (
|
2023-09-18 07:45:14 +00:00
|
|
|
|
<Typography>
|
|
|
|
|
{listQuestions[quizId][totalIndex].content.ratingDescription}
|
|
|
|
|
</Typography>
|
2023-09-12 09:56:15 +00:00
|
|
|
|
) : (
|
|
|
|
|
<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>
|
2023-09-18 07:45:14 +00:00
|
|
|
|
<ButtonsOptions
|
|
|
|
|
switchState={switchState}
|
|
|
|
|
SSHC={SSHC}
|
|
|
|
|
totalIndex={totalIndex}
|
|
|
|
|
/>
|
2023-08-24 11:09:47 +00:00
|
|
|
|
<SwitchRating switchState={switchState} totalIndex={totalIndex} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|