2023-08-18 11:16:56 +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, Link, useTheme, useMediaQuery } from "@mui/material";
|
2023-05-03 19:21:00 +00:00
|
|
|
|
import EnterIcon from "../../../assets/icons/questionsPage/enterIcon";
|
2023-03-15 22:56:53 +00:00
|
|
|
|
import SwitchAnswerOptions from "./switchAnswerOptions";
|
2023-08-25 10:27:43 +00:00
|
|
|
|
import { AnswerDraggableList } from "../AnswerDraggableList";
|
2023-03-30 18:39:59 +00:00
|
|
|
|
import ButtonsOptionsAndPict from "../ButtonsOptionsAndPict";
|
2023-08-18 11:16:56 +00:00
|
|
|
|
import { questionStore, updateQuestionsList } from "@root/questions";
|
2023-04-17 02:27:22 +00:00
|
|
|
|
|
2023-06-30 14:39:07 +00:00
|
|
|
|
interface Props {
|
2023-07-27 17:30:55 +00:00
|
|
|
|
totalIndex: number;
|
2023-06-30 14:39:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 17:30:55 +00:00
|
|
|
|
export default function AnswerOptions({ totalIndex }: Props) {
|
2023-08-18 11:16:56 +00:00
|
|
|
|
const [switchState, setSwitchState] = useState("setting");
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const quizId = Number(useParams().quizId);
|
2023-07-27 17:30:55 +00:00
|
|
|
|
const { listQuestions } = questionStore();
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const variants = listQuestions[quizId][totalIndex].content.variants;
|
2023-07-27 17:30:55 +00:00
|
|
|
|
const theme = useTheme();
|
2023-09-15 12:37:12 +00:00
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
2023-08-18 11:16:56 +00:00
|
|
|
|
|
2023-07-27 17:30:55 +00:00
|
|
|
|
const SSHC = (data: string) => {
|
|
|
|
|
setSwitchState(data);
|
|
|
|
|
};
|
2023-07-11 10:43:04 +00:00
|
|
|
|
|
2023-08-18 09:26:32 +00:00
|
|
|
|
const addNewAnswer = () => {
|
2023-09-15 12:37:12 +00:00
|
|
|
|
const answerNew = variants.slice();
|
2023-09-07 14:14:48 +00:00
|
|
|
|
answerNew.push({ answer: "", hints: "" });
|
2023-08-18 09:26:32 +00:00
|
|
|
|
|
2023-09-06 13:20:12 +00:00
|
|
|
|
updateQuestionsList(quizId, totalIndex, {
|
|
|
|
|
content: {
|
|
|
|
|
...listQuestions[quizId][totalIndex].content,
|
|
|
|
|
variants: answerNew,
|
|
|
|
|
},
|
2023-08-18 09:26:32 +00:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-27 17:30:55 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Box sx={{ padding: "0 20px 20px 20px" }}>
|
2023-08-18 11:16:56 +00:00
|
|
|
|
{variants.length === 0 ? (
|
2023-07-27 17:30:55 +00:00
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
padding: "0 0 33px 80px",
|
|
|
|
|
fontWeight: 400,
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
lineHeight: "21.33px",
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Добавьте ответ
|
|
|
|
|
</Typography>
|
|
|
|
|
) : (
|
2023-08-18 11:16:56 +00:00
|
|
|
|
<AnswerDraggableList variants={variants} totalIndex={totalIndex} />
|
2023-07-27 17:30:55 +00:00
|
|
|
|
)}
|
2023-07-11 10:43:04 +00:00
|
|
|
|
|
2023-08-11 07:25:28 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "10px",
|
|
|
|
|
marginTop: "10px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-07-27 17:30:55 +00:00
|
|
|
|
<Link
|
|
|
|
|
component="button"
|
|
|
|
|
variant="body2"
|
|
|
|
|
sx={{ color: theme.palette.brightPurple.main }}
|
2023-08-18 09:26:32 +00:00
|
|
|
|
onClick={addNewAnswer}
|
2023-07-27 17:30:55 +00:00
|
|
|
|
>
|
|
|
|
|
Добавьте ответ
|
|
|
|
|
</Link>
|
2023-09-15 12:37:12 +00:00
|
|
|
|
{isMobile ? null : (
|
|
|
|
|
<>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontWeight: 400,
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
lineHeight: "21.33px",
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
или нажмите Enter
|
|
|
|
|
</Typography>
|
|
|
|
|
<EnterIcon />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2023-07-27 17:30:55 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2023-09-15 12:37:12 +00:00
|
|
|
|
<ButtonsOptionsAndPict switchState={switchState} SSHC={SSHC} totalIndex={totalIndex} />
|
2023-07-27 17:30:55 +00:00
|
|
|
|
<SwitchAnswerOptions switchState={switchState} totalIndex={totalIndex} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|