2023-09-06 13:20:12 +00:00
|
|
|
import { useParams } from "react-router-dom";
|
2023-08-08 11:01:37 +00:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Checkbox,
|
2023-07-27 17:30:55 +00:00
|
|
|
FormControl,
|
2023-08-08 11:01:37 +00:00
|
|
|
FormControlLabel,
|
|
|
|
IconButton,
|
2023-07-27 17:30:55 +00:00
|
|
|
InputAdornment,
|
2023-08-08 11:01:37 +00:00
|
|
|
Paper,
|
2023-07-27 17:30:55 +00:00
|
|
|
TextField,
|
2023-08-08 11:01:37 +00:00
|
|
|
useTheme,
|
|
|
|
} from "@mui/material";
|
2023-08-11 07:25:28 +00:00
|
|
|
import TypeQuestions from "../TypeQuestions";
|
|
|
|
import SwitchQuestionsPage from "../SwitchQuestionsPage";
|
|
|
|
|
|
|
|
import {
|
|
|
|
questionStore,
|
|
|
|
updateQuestionsList,
|
|
|
|
copyQuestion,
|
|
|
|
removeQuestion,
|
|
|
|
} from "@root/questions";
|
|
|
|
|
2023-06-28 23:32:43 +00:00
|
|
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
2023-08-08 11:01:37 +00:00
|
|
|
import ExpandLessIcon from "@mui/icons-material/ExpandLess";
|
2023-08-11 07:25:28 +00:00
|
|
|
import DeleteIcon from "@icons/questionsPage/deleteIcon";
|
2023-06-28 23:32:43 +00:00
|
|
|
import OneIcon from "@icons/questionsPage/OneIcon";
|
|
|
|
import PointsIcon from "@icons/questionsPage/PointsIcon";
|
2023-06-30 17:59:50 +00:00
|
|
|
import CopyIcon from "@icons/questionsPage/CopyIcon";
|
|
|
|
import CrossedEyeIcon from "@icons/CrossedEyeIcon";
|
|
|
|
import HideIcon from "@icons/questionsPage/hideIcon";
|
2023-07-06 15:54:12 +00:00
|
|
|
import Answer from "@icons/questionsPage/answer";
|
|
|
|
import OptionsPict from "@icons/questionsPage/options_pict";
|
|
|
|
import OptionsAndPict from "@icons/questionsPage/options_and_pict";
|
|
|
|
import Emoji from "@icons/questionsPage/emoji";
|
|
|
|
import Input from "@icons/questionsPage/input";
|
|
|
|
import DropDown from "@icons/questionsPage/drop_down";
|
|
|
|
import Date from "@icons/questionsPage/date";
|
|
|
|
import Slider from "@icons/questionsPage/slider";
|
|
|
|
import Download from "@icons/questionsPage/download";
|
|
|
|
import Page from "@icons/questionsPage/page";
|
|
|
|
import RatingIcon from "@icons/questionsPage/rating";
|
2023-06-28 23:32:43 +00:00
|
|
|
|
2023-08-08 11:01:37 +00:00
|
|
|
import type { DraggableProvidedDragHandleProps } from "react-beautiful-dnd";
|
|
|
|
|
2023-06-28 23:32:43 +00:00
|
|
|
interface Props {
|
2023-08-08 11:01:37 +00:00
|
|
|
totalIndex: number;
|
2023-08-11 07:25:28 +00:00
|
|
|
draggableProps: DraggableProvidedDragHandleProps | null | undefined;
|
2023-06-28 23:32:43 +00:00
|
|
|
}
|
|
|
|
|
2023-07-27 17:30:55 +00:00
|
|
|
const IconAndrom = (isExpanded: boolean, switchState: string) => {
|
|
|
|
switch (switchState) {
|
|
|
|
case "variant":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<Answer
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
case "images":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<OptionsPict
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
case "varimg":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<OptionsAndPict
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
case "emoji":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<Emoji
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
case "text":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<Input
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
case "select":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<DropDown
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
case "date":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<Date
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
case "number":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<Slider
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
case "file":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<Download
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
case "page":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<Page
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
case "rating":
|
2023-08-11 07:25:28 +00:00
|
|
|
return (
|
|
|
|
<RatingIcon
|
|
|
|
color={isExpanded ? "#9A9AAF" : "white"}
|
|
|
|
sx={{ height: "22px", width: "20px" }}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-27 17:30:55 +00:00
|
|
|
default:
|
|
|
|
return <></>;
|
|
|
|
}
|
|
|
|
};
|
2023-08-11 07:25:28 +00:00
|
|
|
export default function QuestionsPageCard({
|
|
|
|
totalIndex,
|
|
|
|
draggableProps,
|
|
|
|
}: Props) {
|
2023-09-06 13:20:12 +00:00
|
|
|
const quizId = Number(useParams().quizId);
|
2023-08-08 11:01:37 +00:00
|
|
|
const theme = useTheme();
|
2023-07-27 17:30:55 +00:00
|
|
|
const { listQuestions } = questionStore();
|
2023-09-06 13:20:12 +00:00
|
|
|
const { type: switchState, expanded: isExpanded } =
|
|
|
|
listQuestions[quizId][totalIndex];
|
2023-07-20 22:02:20 +00:00
|
|
|
|
2023-08-08 11:01:37 +00:00
|
|
|
return (
|
|
|
|
<Paper
|
|
|
|
id={String(totalIndex)}
|
|
|
|
sx={{
|
|
|
|
maxWidth: "796px",
|
|
|
|
width: "100%",
|
|
|
|
borderRadius: "12px",
|
2023-07-27 17:30:55 +00:00
|
|
|
margin: "20px 0",
|
2023-08-08 11:01:37 +00:00
|
|
|
backgroundColor: isExpanded ? "white" : "#333647",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
2023-08-11 07:25:28 +00:00
|
|
|
sx={{
|
|
|
|
width: "100%",
|
|
|
|
maxWidth: "760px",
|
|
|
|
display: "flex",
|
|
|
|
alignItems: "center",
|
|
|
|
gap: "10px",
|
|
|
|
padding: "20px",
|
|
|
|
}}
|
2023-08-08 11:01:37 +00:00
|
|
|
>
|
2023-07-27 17:30:55 +00:00
|
|
|
<FormControl fullWidth variant="standard" sx={{ p: 0 }}>
|
|
|
|
<TextField
|
|
|
|
fullWidth
|
2023-09-06 13:20:12 +00:00
|
|
|
value={listQuestions[quizId][totalIndex].title}
|
2023-07-27 17:30:55 +00:00
|
|
|
placeholder={"Заголовок вопроса"}
|
|
|
|
onChange={(e) => {
|
2023-09-06 13:20:12 +00:00
|
|
|
updateQuestionsList(quizId, totalIndex, {
|
|
|
|
title: e.target.value,
|
|
|
|
});
|
|
|
|
console.log(listQuestions[quizId][totalIndex].title);
|
2023-07-27 17:30:55 +00:00
|
|
|
}}
|
|
|
|
InputProps={{
|
2023-08-11 07:25:28 +00:00
|
|
|
startAdornment: (
|
|
|
|
<InputAdornment position="start">
|
|
|
|
{IconAndrom(isExpanded, switchState)}
|
|
|
|
</InputAdornment>
|
|
|
|
),
|
2023-07-27 17:30:55 +00:00
|
|
|
}}
|
2023-06-30 19:10:47 +00:00
|
|
|
sx={{
|
2023-07-27 17:30:55 +00:00
|
|
|
"& .MuiInputBase-root": {
|
|
|
|
color: isExpanded ? "#9A9AAF" : "white",
|
2023-08-11 07:25:28 +00:00
|
|
|
backgroundColor: isExpanded
|
|
|
|
? theme.palette.background.default
|
|
|
|
: "transparent",
|
2023-07-27 17:30:55 +00:00
|
|
|
height: "48px",
|
|
|
|
borderRadius: "10px",
|
|
|
|
},
|
2023-06-30 19:10:47 +00:00
|
|
|
}}
|
2023-07-27 17:30:55 +00:00
|
|
|
inputProps={{
|
|
|
|
sx: {
|
|
|
|
borderRadius: "10px",
|
|
|
|
fontSize: "18px",
|
|
|
|
lineHeight: "21px",
|
|
|
|
py: 0,
|
|
|
|
paddingLeft: switchState.length === 0 ? 0 : "18px",
|
|
|
|
},
|
2023-06-30 19:10:47 +00:00
|
|
|
}}
|
2023-08-08 11:01:37 +00:00
|
|
|
/>
|
2023-07-27 17:30:55 +00:00
|
|
|
</FormControl>
|
2023-07-22 20:07:57 +00:00
|
|
|
|
2023-08-18 07:48:16 +00:00
|
|
|
<IconButton
|
|
|
|
onClick={() =>
|
2023-09-06 13:20:12 +00:00
|
|
|
updateQuestionsList(quizId, totalIndex, { expanded: !isExpanded })
|
2023-08-18 07:48:16 +00:00
|
|
|
}
|
|
|
|
>
|
2023-08-03 17:36:42 +00:00
|
|
|
{isExpanded ? <ExpandMoreIcon /> : <ExpandLessIcon fill="#7E2AEA" />}
|
|
|
|
</IconButton>
|
2023-07-27 17:30:55 +00:00
|
|
|
{isExpanded ? (
|
|
|
|
<></>
|
|
|
|
) : (
|
|
|
|
<Box sx={{ display: "flex", borderRight: "solid 1px white" }}>
|
|
|
|
<FormControlLabel
|
2023-08-11 07:25:28 +00:00
|
|
|
control={
|
|
|
|
<Checkbox
|
|
|
|
icon={<HideIcon color={"#7E2AEA"} />}
|
|
|
|
checkedIcon={<CrossedEyeIcon />}
|
|
|
|
/>
|
|
|
|
}
|
2023-07-27 17:30:55 +00:00
|
|
|
label={""}
|
|
|
|
sx={{
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
ml: "-9px",
|
|
|
|
mr: 0,
|
|
|
|
userSelect: "none",
|
|
|
|
}}
|
|
|
|
/>
|
2023-09-06 13:20:12 +00:00
|
|
|
<IconButton onClick={() => copyQuestion(quizId, totalIndex)}>
|
2023-07-27 17:30:55 +00:00
|
|
|
<CopyIcon color={"white"} />
|
|
|
|
</IconButton>
|
2023-08-11 07:25:28 +00:00
|
|
|
<IconButton
|
|
|
|
sx={{ cursor: "pointer", borderRadius: "6px", padding: "2px" }}
|
2023-09-06 13:20:12 +00:00
|
|
|
onClick={() => removeQuestion(quizId, totalIndex)}
|
2023-08-11 07:25:28 +00:00
|
|
|
>
|
2023-07-27 17:30:55 +00:00
|
|
|
<DeleteIcon color={"white"} />
|
|
|
|
</IconButton>
|
|
|
|
</Box>
|
|
|
|
)}
|
2023-06-28 23:32:43 +00:00
|
|
|
|
2023-08-08 11:01:37 +00:00
|
|
|
<OneIcon />
|
2023-08-11 07:25:28 +00:00
|
|
|
<IconButton {...draggableProps}>
|
2023-08-08 11:01:37 +00:00
|
|
|
<PointsIcon />
|
2023-07-27 17:30:55 +00:00
|
|
|
</IconButton>
|
2023-08-08 11:01:37 +00:00
|
|
|
</Box>
|
|
|
|
{isExpanded && (
|
2023-08-11 07:25:28 +00:00
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
padding: 0,
|
|
|
|
borderRadius: "12px",
|
|
|
|
}}
|
|
|
|
>
|
2023-08-08 11:01:37 +00:00
|
|
|
{switchState.length === 0 ? (
|
|
|
|
<TypeQuestions totalIndex={totalIndex} />
|
|
|
|
) : (
|
|
|
|
<SwitchQuestionsPage totalIndex={totalIndex} />
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</Paper>
|
|
|
|
);
|
|
|
|
}
|