2023-07-27 17:30:55 +00:00
|
|
|
|
import { Box, Typography, Link, useTheme, TextField, FormControl, InputAdornment, IconButton } from "@mui/material";
|
|
|
|
|
import React, { useState } from "react";
|
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-03-30 18:39:59 +00:00
|
|
|
|
import ButtonsOptionsAndPict from "../ButtonsOptionsAndPict";
|
2023-07-06 15:54:12 +00:00
|
|
|
|
import QuestionsPageCard from "../QuestionPageCard";
|
2023-07-27 17:30:55 +00:00
|
|
|
|
import { useParams } from "react-router-dom";
|
2023-07-30 16:02:41 +00:00
|
|
|
|
import { Variants, questionStore, updateQuestionsList } from "@root/questions";
|
2023-07-11 10:43:04 +00:00
|
|
|
|
import PointsIcon from "@icons/questionsPage/PointsIcon";
|
|
|
|
|
import DeleteIcon from "@icons/questionsPage/deleteIcon";
|
|
|
|
|
import MessageIcon from "@icons/messagIcon";
|
2023-07-27 17:30:55 +00:00
|
|
|
|
import Popover from "@mui/material/Popover";
|
|
|
|
|
import TextareaAutosize from "@mui/base/TextareaAutosize";
|
2023-04-17 02:27:22 +00:00
|
|
|
|
|
2023-07-30 16:02:41 +00:00
|
|
|
|
// Импортируем интерфейс Varian
|
|
|
|
|
|
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) {
|
|
|
|
|
const { listQuestions } = questionStore();
|
|
|
|
|
const Answer = listQuestions[totalIndex].content.variants;
|
|
|
|
|
console.log(Answer);
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const [switchState, setSwitchState] = React.useState("setting");
|
|
|
|
|
const SSHC = (data: string) => {
|
|
|
|
|
setSwitchState(data);
|
|
|
|
|
};
|
2023-07-11 10:43:04 +00:00
|
|
|
|
|
2023-07-30 16:02:41 +00:00
|
|
|
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
|
|
|
const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null); // Объявление состояния для anchorEl
|
2023-07-11 10:43:04 +00:00
|
|
|
|
|
2023-07-27 17:30:55 +00:00
|
|
|
|
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
|
setAnchorEl(event.currentTarget);
|
2023-07-30 16:02:41 +00:00
|
|
|
|
setIsOpen(true);
|
2023-07-27 17:30:55 +00:00
|
|
|
|
};
|
2023-07-11 10:43:04 +00:00
|
|
|
|
|
2023-07-27 17:30:55 +00:00
|
|
|
|
const handleClose = () => {
|
2023-07-30 16:02:41 +00:00
|
|
|
|
setIsOpen(false);
|
2023-07-27 17:30:55 +00:00
|
|
|
|
};
|
2023-07-11 10:43:04 +00:00
|
|
|
|
|
2023-07-30 16:02:41 +00:00
|
|
|
|
const id = "my-popover-id";
|
|
|
|
|
|
2023-07-27 17:30:55 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Box sx={{ padding: "0 20px 20px 20px" }}>
|
|
|
|
|
{Answer.length === 0 ? (
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
padding: "0 0 33px 80px",
|
|
|
|
|
fontWeight: 400,
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
lineHeight: "21.33px",
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Добавьте ответ
|
|
|
|
|
</Typography>
|
|
|
|
|
) : (
|
|
|
|
|
<Box>
|
2023-07-30 16:02:41 +00:00
|
|
|
|
{Answer.map((variant: Variants, index: number) => (
|
|
|
|
|
<FormControl key={index} fullWidth variant="standard" sx={{ p: "0 0 20px 0" }}>
|
2023-07-27 17:30:55 +00:00
|
|
|
|
<TextField
|
2023-07-30 16:02:41 +00:00
|
|
|
|
value={variant.answer}
|
2023-07-27 17:30:55 +00:00
|
|
|
|
fullWidth
|
|
|
|
|
placeholder={"Добавьте ответ"}
|
|
|
|
|
onChange={(e) => {
|
2023-07-30 16:02:41 +00:00
|
|
|
|
const answerNew = Answer.slice(); // Create a shallow copy of the array
|
2023-07-27 17:30:55 +00:00
|
|
|
|
answerNew[index].answer = e.target.value;
|
|
|
|
|
let clonContent = listQuestions[totalIndex].content;
|
|
|
|
|
clonContent.variants = answerNew;
|
|
|
|
|
updateQuestionsList(totalIndex, { content: clonContent });
|
|
|
|
|
}}
|
|
|
|
|
InputProps={{
|
|
|
|
|
startAdornment: (
|
|
|
|
|
<InputAdornment position="start">
|
|
|
|
|
<PointsIcon />
|
|
|
|
|
</InputAdornment>
|
|
|
|
|
),
|
|
|
|
|
endAdornment: (
|
|
|
|
|
<InputAdornment position="end">
|
|
|
|
|
<IconButton aria-describedby={id} onClick={handleClick}>
|
|
|
|
|
<MessageIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<Popover
|
|
|
|
|
id={id}
|
2023-07-30 16:02:41 +00:00
|
|
|
|
open={isOpen}
|
2023-07-27 17:30:55 +00:00
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
anchorOrigin={{
|
|
|
|
|
vertical: "bottom",
|
|
|
|
|
horizontal: "left",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<TextareaAutosize
|
|
|
|
|
style={{ margin: "10px" }}
|
|
|
|
|
placeholder="Подсказка для этого ответа"
|
2023-07-30 16:02:41 +00:00
|
|
|
|
value={variant.hints}
|
2023-07-27 17:30:55 +00:00
|
|
|
|
onChange={(e) => {
|
2023-07-30 16:02:41 +00:00
|
|
|
|
const answerNew = Answer.slice(); // Create a shallow copy of the array
|
2023-07-27 17:30:55 +00:00
|
|
|
|
answerNew[index].hints = e.target.value;
|
|
|
|
|
let clonContent = listQuestions[totalIndex].content;
|
|
|
|
|
clonContent.variants = answerNew;
|
|
|
|
|
updateQuestionsList(totalIndex, { content: clonContent });
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Popover>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
2023-07-30 16:02:41 +00:00
|
|
|
|
const answerNew = Answer.slice(); // Create a shallow copy of the array
|
2023-07-27 17:30:55 +00:00
|
|
|
|
answerNew.splice(index, 1);
|
|
|
|
|
let clonContent = listQuestions[totalIndex].content;
|
|
|
|
|
clonContent.variants = answerNew;
|
|
|
|
|
updateQuestionsList(totalIndex, { content: clonContent });
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DeleteIcon color={theme.palette.grey2.main} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</InputAdornment>
|
|
|
|
|
),
|
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
"& .MuiInputBase-root": {
|
|
|
|
|
height: "48px",
|
|
|
|
|
borderRadius: "10px",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
inputProps={{
|
|
|
|
|
sx: {
|
|
|
|
|
borderRadius: "10px",
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
lineHeight: "21px",
|
|
|
|
|
py: 0,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</FormControl>
|
|
|
|
|
))}
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2023-07-11 10:43:04 +00:00
|
|
|
|
|
2023-07-27 17:30:55 +00:00
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", gap: "10px", marginTop: "10px" }}>
|
|
|
|
|
<Link
|
|
|
|
|
component="button"
|
|
|
|
|
variant="body2"
|
|
|
|
|
sx={{ color: theme.palette.brightPurple.main }}
|
|
|
|
|
onClick={() => {
|
2023-07-30 16:02:41 +00:00
|
|
|
|
const answerNew = Answer.slice(); // Create a shallow copy of the array
|
|
|
|
|
answerNew.push({
|
|
|
|
|
answer: "",
|
|
|
|
|
answerLong: "",
|
|
|
|
|
hints: "",
|
|
|
|
|
});
|
2023-07-27 17:30:55 +00:00
|
|
|
|
let clonContent = listQuestions[totalIndex].content;
|
|
|
|
|
clonContent.variants = answerNew;
|
|
|
|
|
updateQuestionsList(totalIndex, { content: clonContent });
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Добавьте ответ
|
|
|
|
|
</Link>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontWeight: 400,
|
|
|
|
|
fontSize: "18px",
|
|
|
|
|
lineHeight: "21.33px",
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
или нажмите Enter
|
|
|
|
|
</Typography>
|
|
|
|
|
<EnterIcon />
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
<ButtonsOptionsAndPict switchState={switchState} SSHC={SSHC} totalIndex={totalIndex} />
|
|
|
|
|
<SwitchAnswerOptions switchState={switchState} totalIndex={totalIndex} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|