2023-11-29 15:45:15 +00:00
|
|
|
|
import { useParams } from "react-router-dom";
|
2023-12-05 23:34:40 +00:00
|
|
|
|
import { Box, Button, IconButton, Typography } from "@mui/material";
|
2023-11-29 15:45:15 +00:00
|
|
|
|
import { ReactComponent as CheckedIcon } from "@icons/checked.svg";
|
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
2023-12-01 19:56:13 +00:00
|
|
|
|
import { updateDragQuestionContentId } from "@root/questions/actions";
|
2023-11-29 15:45:15 +00:00
|
|
|
|
import { useEffect } from "react";
|
2023-12-01 08:12:59 +00:00
|
|
|
|
import { AnyTypedQuizQuestion, UntypedQuizQuestion } from "@model/questionTypes/shared";
|
2023-12-05 23:34:40 +00:00
|
|
|
|
import { Pencil } from "../../startPage/Sidebar/icons/Pencil";
|
|
|
|
|
import {updateOpenBranchingPanel, updateEditSomeQuestion} from "@root/questions/actions"
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
|
|
|
|
|
2023-12-05 23:34:40 +00:00
|
|
|
|
const getItemStyle = (isDragging: any, draggableStyle: any) => ({
|
2023-11-29 15:45:15 +00:00
|
|
|
|
// some basic styles to make the items look a bit nicer
|
|
|
|
|
userSelect: "none",
|
|
|
|
|
padding: 5 * 2,
|
|
|
|
|
margin: `0 0 5px 0`,
|
|
|
|
|
|
|
|
|
|
// change background colour if dragging
|
|
|
|
|
background: isDragging ? "lightgreen" : "grey",
|
|
|
|
|
|
|
|
|
|
// styles we need to apply on draggables
|
|
|
|
|
...draggableStyle
|
|
|
|
|
});
|
2023-12-01 08:12:59 +00:00
|
|
|
|
type AnyQuestion = UntypedQuizQuestion | AnyTypedQuizQuestion
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
|
|
|
|
export const QuestionsList = () => {
|
2023-12-07 22:56:31 +00:00
|
|
|
|
const { desireToOpenABranchingModal } = useQuestionsStore()
|
|
|
|
|
const trashQuestions = useQuestionsStore().questions
|
|
|
|
|
const questions = trashQuestions.filter((question) => question.type !== "result")
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box sx={{ padding: "15px" }}>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{ fontSize: "12px", color: "#9A9AAF", marginBottom: "5px" }}
|
|
|
|
|
>
|
|
|
|
|
Перетащите вопросы в карту ветвления
|
|
|
|
|
</Typography>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
maxHeight: "400px",
|
|
|
|
|
overflowY: "scroll",
|
|
|
|
|
paddingRight: "12px",
|
|
|
|
|
"&::-webkit-scrollbar": { width: "8px" },
|
|
|
|
|
"&::-webkit-scrollbar-track": {
|
|
|
|
|
background: "#D4D4DF",
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
},
|
|
|
|
|
"&::-webkit-scrollbar-thumb": {
|
|
|
|
|
boxSizing: "border-box",
|
|
|
|
|
background: "#9A9AAF",
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
border: "1.5px solid transparent",
|
|
|
|
|
backgroundClip: "padding-box",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{/* тут нужно будет фильтровать с проверкой, что вопрос имеет тип*/}
|
2023-12-05 23:34:40 +00:00
|
|
|
|
{questions.filter((q: AnyQuestion) => q.type).map(({ title, content }, index) => (
|
|
|
|
|
<Button
|
|
|
|
|
onMouseDown={() => {//Разрешаем добавить этот вопрос если у него нет родителя (не добавляли ещё в дерево)
|
|
|
|
|
if (!content.rule.parentId) updateDragQuestionContentId(content.id)
|
|
|
|
|
}}
|
2023-11-29 15:45:15 +00:00
|
|
|
|
key={index}
|
|
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
padding: "12px",
|
|
|
|
|
background: "#FFFFFF",
|
|
|
|
|
borderRadius: "8px",
|
2023-12-05 23:34:40 +00:00
|
|
|
|
border: desireToOpenABranchingModal === content.id ? "4px solid #7e2aea" : "none",
|
2023-11-29 15:45:15 +00:00
|
|
|
|
marginBottom: "20px",
|
|
|
|
|
boxShadow: "0px 10px 30px #e7e7e7",
|
|
|
|
|
backgroundImage: `url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='8' ry='8' stroke='rgb(154, 154, 175)' stroke-width='2' stroke-dasharray='8 8' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e");
|
|
|
|
|
border-radius: 8px;`,
|
|
|
|
|
"&:last-child": { marginBottom: 0 },
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-05 23:34:40 +00:00
|
|
|
|
<Typography sx={{ width: "100%", color: content.rule.parentId ? "#9A9AAF" : "#000" }}>
|
2023-11-29 15:45:15 +00:00
|
|
|
|
{title || "нет заголовка"}
|
|
|
|
|
</Typography>
|
2023-12-05 23:34:40 +00:00
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
updateOpenBranchingPanel(false)
|
|
|
|
|
updateEditSomeQuestion(content.id)
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-09 00:22:19 +00:00
|
|
|
|
<Pencil style={{color: "#7e2aea"}}/>
|
2023-12-05 23:34:40 +00:00
|
|
|
|
</IconButton>
|
2023-11-29 15:45:15 +00:00
|
|
|
|
{content.rule.parentId && <CheckedIcon />}
|
|
|
|
|
</Button>
|
2023-12-05 23:34:40 +00:00
|
|
|
|
|
|
|
|
|
|
2023-11-29 15:45:15 +00:00
|
|
|
|
))}
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|