2023-07-11 10:43:04 +00:00
|
|
|
|
import {Box, Typography, Link, useTheme, TextField, FormControl, InputAdornment, IconButton} from "@mui/material";
|
2023-07-14 11:43:28 +00:00
|
|
|
|
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";
|
|
|
|
|
import {useParams} from "react-router-dom";
|
2023-07-20 22:02:20 +00:00
|
|
|
|
import { 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";
|
|
|
|
|
import Popover from '@mui/material/Popover';
|
|
|
|
|
import TextareaAutosize from '@mui/base/TextareaAutosize';
|
2023-04-17 02:27:22 +00:00
|
|
|
|
|
2023-06-30 14:39:07 +00:00
|
|
|
|
interface Props {
|
|
|
|
|
totalIndex: number,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function AnswerOptions({totalIndex}: Props) {
|
2023-07-06 15:54:12 +00:00
|
|
|
|
const params = Number(useParams().quizId);
|
2023-07-11 10:43:04 +00:00
|
|
|
|
|
2023-07-20 22:02:20 +00:00
|
|
|
|
const {listQuestions} = questionStore()
|
|
|
|
|
const Answer = listQuestions[totalIndex].content.variants
|
2023-07-11 10:43:04 +00:00
|
|
|
|
console.log(Answer)
|
2023-04-17 02:27:22 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const [switchState, setSwitchState] = React.useState('setting');
|
|
|
|
|
const SSHC = (data: string) => {
|
|
|
|
|
setSwitchState(data)
|
|
|
|
|
}
|
2023-07-14 11:43:28 +00:00
|
|
|
|
// const [openBranch, setOpenBranch] = useState(false);
|
|
|
|
|
// const handleOpenBranch = () => setOpenBranch(true);
|
|
|
|
|
// const handleCloseBranch = () => setOpenBranch(false);
|
2023-07-11 10:43:04 +00:00
|
|
|
|
|
|
|
|
|
const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null);
|
|
|
|
|
|
|
|
|
|
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
|
setAnchorEl(event.currentTarget);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
|
setAnchorEl(null);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const open = Boolean(anchorEl);
|
|
|
|
|
const id = open ? 'simple-popover' : undefined;
|
2023-04-17 02:27:22 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
2023-07-11 10:43:04 +00:00
|
|
|
|
<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>
|
|
|
|
|
{Answer.map((answer:string, index:number) => (
|
|
|
|
|
<FormControl
|
|
|
|
|
fullWidth
|
|
|
|
|
variant="standard"
|
|
|
|
|
sx={{ p: "0 0 20px 0" }}
|
|
|
|
|
>
|
|
|
|
|
<TextField
|
2023-07-14 11:43:28 +00:00
|
|
|
|
value={Answer[index].answer}
|
2023-07-11 10:43:04 +00:00
|
|
|
|
fullWidth
|
|
|
|
|
placeholder={"Добавьте ответ"}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
const answerNew = Answer
|
2023-07-14 11:43:28 +00:00
|
|
|
|
answerNew[index].answer = e.target.value
|
2023-07-20 22:02:20 +00:00
|
|
|
|
let clonContent = listQuestions[totalIndex].content
|
2023-07-12 21:24:12 +00:00
|
|
|
|
clonContent.variants = answerNew
|
2023-07-20 22:02:20 +00:00
|
|
|
|
updateQuestionsList(totalIndex, {content: clonContent})}}
|
2023-07-11 10:43:04 +00:00
|
|
|
|
InputProps={{
|
|
|
|
|
startAdornment: (
|
|
|
|
|
<InputAdornment position="start">
|
|
|
|
|
<PointsIcon />
|
|
|
|
|
</InputAdornment>
|
|
|
|
|
),
|
|
|
|
|
endAdornment: (
|
|
|
|
|
<InputAdornment position="end">
|
|
|
|
|
<IconButton aria-describedby={id} onClick={handleClick}>
|
|
|
|
|
<MessageIcon/>
|
|
|
|
|
</IconButton>
|
|
|
|
|
<Popover
|
|
|
|
|
id={id}
|
|
|
|
|
open={open}
|
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
anchorOrigin={{
|
|
|
|
|
vertical: 'bottom',
|
|
|
|
|
horizontal: 'left',
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-07-14 11:43:28 +00:00
|
|
|
|
<TextareaAutosize style={{margin: "10px"}} placeholder="Подсказка для этого ответа" value={Answer[index].hints}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
const answerNew = Answer
|
|
|
|
|
answerNew[index].hints = e.target.value
|
2023-07-20 22:02:20 +00:00
|
|
|
|
let clonContent = listQuestions[totalIndex].content
|
2023-07-14 11:43:28 +00:00
|
|
|
|
clonContent.variants = answerNew
|
2023-07-20 22:02:20 +00:00
|
|
|
|
updateQuestionsList(totalIndex, {content: clonContent})}}
|
2023-07-14 11:43:28 +00:00
|
|
|
|
/>
|
2023-07-11 10:43:04 +00:00
|
|
|
|
</Popover>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const answerNew = Answer
|
|
|
|
|
answerNew.splice(index, 1)
|
2023-07-20 22:02:20 +00:00
|
|
|
|
let clonContent = listQuestions[totalIndex].content
|
2023-07-12 21:24:12 +00:00
|
|
|
|
clonContent.variants = answerNew
|
2023-07-20 22:02:20 +00:00
|
|
|
|
updateQuestionsList(totalIndex, {content: clonContent})
|
2023-07-11 10:43:04 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<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>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: '10px', marginTop: "10px"}}>
|
2023-04-17 02:27:22 +00:00
|
|
|
|
<Link
|
|
|
|
|
component="button"
|
|
|
|
|
variant="body2"
|
|
|
|
|
sx={{color: theme.palette.brightPurple.main}}
|
2023-07-06 15:54:12 +00:00
|
|
|
|
onClick={() => {
|
2023-07-11 10:43:04 +00:00
|
|
|
|
const answerNew = Answer
|
2023-07-14 11:43:28 +00:00
|
|
|
|
answerNew.push({answer: "",})
|
2023-07-20 22:02:20 +00:00
|
|
|
|
let clonContent = listQuestions[totalIndex].content
|
2023-07-12 21:24:12 +00:00
|
|
|
|
clonContent.variants = answerNew
|
2023-07-20 22:02:20 +00:00
|
|
|
|
updateQuestionsList(totalIndex, {content: clonContent})
|
2023-07-06 15:54:12 +00:00
|
|
|
|
}}
|
2023-04-17 02:27:22 +00:00
|
|
|
|
>
|
|
|
|
|
Добавьте ответ
|
|
|
|
|
</Link>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontWeight: 400,
|
|
|
|
|
fontSize: '18px',
|
|
|
|
|
lineHeight: '21.33px',
|
|
|
|
|
color: theme.palette.grey2.main
|
|
|
|
|
}}
|
|
|
|
|
>или нажмите Enter</Typography>
|
|
|
|
|
<EnterIcon/>
|
|
|
|
|
</Box>
|
2023-07-06 15:54:12 +00:00
|
|
|
|
|
|
|
|
|
|
2023-04-17 02:27:22 +00:00
|
|
|
|
</Box>
|
2023-06-30 14:39:07 +00:00
|
|
|
|
<ButtonsOptionsAndPict switchState={switchState} SSHC={SSHC} totalIndex={totalIndex}/>
|
2023-07-11 10:43:04 +00:00
|
|
|
|
<SwitchAnswerOptions switchState={switchState} totalIndex={totalIndex}/>
|
2023-04-17 02:27:22 +00:00
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|