frontPanel/src/pages/Questions/ButtonsOptions.tsx

264 lines
8.2 KiB
TypeScript
Raw Normal View History

2023-09-27 14:14:48 +00:00
import { useState, useEffect } from "react";
import MiniButtonSetting from "@ui_kit/MiniButtonSetting";
2023-09-08 14:06:18 +00:00
import { useParams } from "react-router-dom";
import SettingIcon from "../../assets/icons/questionsPage/settingIcon";
import Clue from "../../assets/icons/questionsPage/clue";
import Branching from "../../assets/icons/questionsPage/branching";
2023-09-15 12:37:12 +00:00
import { Box, Typography, Tooltip, IconButton, useTheme, useMediaQuery } from "@mui/material";
2023-09-25 13:43:15 +00:00
import { HideIcon } from "../../assets/icons/questionsPage/hideIcon";
import { CopyIcon } from "../../assets/icons/questionsPage/CopyIcon";
2023-09-29 04:24:06 +00:00
import { questionStore, resetSomeField, copyQuestion, removeQuestionForce, updateQuestionsList, removeQuestion } from "@root/questions";
2023-09-21 07:00:08 +00:00
import { DoubleTick } from "@icons/questionsPage/DoubleTick";
import { DoubleArrowRight } from "@icons/questionsPage/DoubleArrowRight";
import { VectorQuestions } from "@icons/questionsPage/VectorQuestions";
2023-09-25 13:43:15 +00:00
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
interface Props {
2023-04-15 09:10:59 +00:00
switchState: string;
SSHC: (data: string) => void;
2023-09-08 14:06:18 +00:00
totalIndex: number;
}
2023-09-22 07:26:07 +00:00
export default function ButtonsOptions({
SSHC,
switchState,
totalIndex,
}: Props) {
2023-09-06 13:20:12 +00:00
const quizId = Number(useParams().quizId);
2023-09-27 14:14:48 +00:00
const { openedModalSettings, listQuestions } = questionStore();
2023-09-22 07:26:07 +00:00
const [openedReallyChangingModal, setOpenedReallyChangingModal] =
useState<boolean>(false);
2023-09-21 07:00:08 +00:00
2023-09-27 14:14:48 +00:00
useEffect(() => {
if (listQuestions[quizId][totalIndex].deleteTimeoutId) {
clearTimeout(listQuestions[quizId][totalIndex].deleteTimeoutId);
}
}, [listQuestions]);
2023-09-21 07:00:08 +00:00
const openedModal = () => {
2023-09-08 14:06:18 +00:00
resetSomeField({ openedModalSettings: "open" });
};
2023-09-20 17:39:17 +00:00
2023-04-15 09:10:59 +00:00
const theme = useTheme();
2023-09-15 12:37:12 +00:00
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
const isMobile = useMediaQuery(theme.breakpoints.down(790));
2023-09-21 07:00:08 +00:00
const isWrappMiniButtonSetting = useMediaQuery(theme.breakpoints.down(920));
2023-09-08 14:06:18 +00:00
const buttonSetting: {
icon: JSX.Element;
title: string;
value: string;
myFunc?: any;
}[] = [
2023-04-15 09:10:59 +00:00
{
2023-09-22 07:26:07 +00:00
icon: (
<SettingIcon
color={
switchState === "setting" ? "#ffffff" : theme.palette.grey3.main
}
/>
),
2023-04-15 09:10:59 +00:00
title: "Настройки",
value: "setting",
},
{
2023-09-22 07:26:07 +00:00
icon: (
<Clue
color={switchState === "help" ? "#ffffff" : theme.palette.grey3.main}
/>
),
2023-04-15 09:10:59 +00:00
title: "Подсказка",
value: "help",
},
{
2023-09-22 07:26:07 +00:00
icon: (
<Branching
color={
switchState === "branching" ? "#ffffff" : theme.palette.grey3.main
}
/>
),
2023-04-15 09:10:59 +00:00
title: "Ветвление",
value: "branching",
2023-09-08 14:06:18 +00:00
myFunc: openedModal,
2023-04-15 09:10:59 +00:00
},
];
2023-04-15 09:10:59 +00:00
return (
<Box
sx={{
display: "flex",
2023-09-25 13:43:15 +00:00
alignItems: "center",
2023-04-15 09:10:59 +00:00
justifyContent: "space-between",
width: "100%",
2023-09-25 13:43:15 +00:00
background: "#f2f3f7",
height: isMobile ? "92px" : "70px",
2023-04-15 09:10:59 +00:00
}}
>
<Box
sx={{
2023-09-25 13:43:15 +00:00
padding: isMobile ? " 3px 12px 11px" : "20px",
2023-04-15 09:10:59 +00:00
display: "flex",
2023-09-15 12:37:12 +00:00
flexWrap: isMobile ? "wrap" : "nowrap",
2023-09-25 13:43:15 +00:00
gap: "6px",
2023-04-15 09:10:59 +00:00
}}
>
2023-09-08 14:06:18 +00:00
{buttonSetting.map(({ icon, title, value, myFunc }) => (
2023-09-21 10:07:30 +00:00
<Box key={value}>
2023-09-08 14:06:18 +00:00
{value === "branching" ? (
<Tooltip
arrow
placement="right"
title={
<Box>
<Typography
sx={{
color: "#4D4D4D",
fontWeight: "bold",
fontSize: "14px",
marginBottom: "10px",
}}
>
Будет показан при условии
</Typography>
2023-09-22 07:26:07 +00:00
<Typography sx={{ fontWeight: "bold", fontSize: "12px" }}>
Название
</Typography>
2023-09-08 14:06:18 +00:00
<Typography
sx={{
fontWeight: "bold",
fontSize: "12px",
marginBottom: "10px",
}}
>
Условие 1, Условие 2
</Typography>
2023-09-22 07:26:07 +00:00
<Typography sx={{ color: "#7E2AEA", fontSize: "12px" }}>
Все условия обязательны
</Typography>
2023-09-08 14:06:18 +00:00
</Box>
}
>
<MiniButtonSetting
key={title}
onClick={() => {
SSHC(value);
myFunc();
}}
sx={{
2023-09-22 07:26:07 +00:00
backgroundColor:
switchState === value
? theme.palette.brightPurple.main
: "transparent",
color:
switchState === value
? "#ffffff"
: theme.palette.grey3.main,
2023-09-21 07:00:08 +00:00
minWidth: isWrappMiniButtonSetting ? "30px" : "64px",
2023-09-15 12:37:12 +00:00
height: "30px",
2023-09-08 14:06:18 +00:00
}}
>
{icon}
2023-09-15 12:37:12 +00:00
2023-09-21 07:00:08 +00:00
{isWrappMiniButtonSetting ? null : title}
2023-09-08 14:06:18 +00:00
</MiniButtonSetting>
</Tooltip>
) : (
<MiniButtonSetting
key={title}
onClick={() => {
SSHC(value);
myFunc();
}}
sx={{
2023-09-22 07:26:07 +00:00
backgroundColor:
switchState === value
? theme.palette.brightPurple.main
: "transparent",
color:
switchState === value
? "#ffffff"
: theme.palette.grey3.main,
2023-09-20 17:39:17 +00:00
minWidth: isWrappMiniButtonSetting ? "30px" : "64px",
2023-09-15 12:37:12 +00:00
height: "30px",
2023-09-08 14:06:18 +00:00
}}
>
{icon}
2023-09-20 17:39:17 +00:00
{isWrappMiniButtonSetting ? null : title}
2023-09-08 14:06:18 +00:00
</MiniButtonSetting>
)}
2023-09-21 10:07:30 +00:00
</Box>
2023-04-15 09:10:59 +00:00
))}
2023-09-21 07:00:08 +00:00
<MiniButtonSetting
onClick={() => setOpenedReallyChangingModal(true)}
sx={{
minWidth: "30px",
height: "30px",
backgroundColor: "#FEDFD0",
}}
>
<DoubleTick style={{ color: "#FC712F", fontSize: "9px" }} />
</MiniButtonSetting>
<MiniButtonSetting
onClick={() => setOpenedReallyChangingModal(true)}
sx={{
minWidth: "30px",
height: "30px",
backgroundColor: "#FEDFD0",
}}
>
<DoubleArrowRight style={{ color: "#FC712F", fontSize: "9px" }} />
</MiniButtonSetting>
<MiniButtonSetting
onClick={() => setOpenedReallyChangingModal(true)}
sx={{
minWidth: "30px",
height: "30px",
backgroundColor: "#FEDFD0",
}}
>
<VectorQuestions style={{ color: "#FC712F", fontSize: "9px" }} />
</MiniButtonSetting>
2023-04-15 09:10:59 +00:00
</Box>
<Box
sx={{
padding: "20px",
2023-09-15 12:37:12 +00:00
display: "flex",
2023-04-15 09:10:59 +00:00
}}
>
<IconButton sx={{ borderRadius: "6px", padding: "2px" }}>
2023-09-25 13:43:15 +00:00
<HideIcon style={{ color: "#4D4D4D" }} />
2023-04-15 09:10:59 +00:00
</IconButton>
2023-09-22 07:26:07 +00:00
<IconButton
sx={{ borderRadius: "6px", padding: "2px" }}
onClick={() => copyQuestion(quizId, totalIndex)}
>
2023-09-08 14:06:18 +00:00
<CopyIcon color={"#4D4D4D"} />
2023-04-15 09:10:59 +00:00
</IconButton>
2023-09-22 07:26:07 +00:00
<IconButton
sx={{ borderRadius: "6px", padding: "2px" }}
2023-09-27 14:14:48 +00:00
onClick={() => {
const removedId = listQuestions[quizId][totalIndex].id;
if (listQuestions[quizId][totalIndex].deleteTimeoutId) {
clearTimeout(listQuestions[quizId][totalIndex].deleteTimeoutId);
}
removeQuestion(quizId, totalIndex);
const newTimeoutId = window.setTimeout(() => {
removeQuestionForce(quizId, removedId);
}, 5000);
updateQuestionsList(quizId, totalIndex, {
...listQuestions[quizId][totalIndex],
deleteTimeoutId: newTimeoutId,
});
}}
2023-09-22 07:26:07 +00:00
>
2023-09-08 14:06:18 +00:00
<DeleteIcon color={"#4D4D4D"} />
2023-04-15 09:10:59 +00:00
</IconButton>
</Box>
</Box>
);
2023-09-29 04:24:06 +00:00
}