2023-11-29 13:49:52 +00:00
|
|
|
|
import { AnyTypedQuizQuestion, UntypedQuizQuestion } from "@model/questionTypes/shared";
|
2023-11-14 20:15:52 +00:00
|
|
|
|
import { Box, ListItem, Typography, useTheme } from "@mui/material";
|
2023-12-05 23:34:40 +00:00
|
|
|
|
import { memo, useEffect } from "react";
|
2023-08-11 07:25:28 +00:00
|
|
|
|
import { Draggable } from "react-beautiful-dnd";
|
|
|
|
|
import QuestionsPageCard from "./QuestionPageCard";
|
2023-12-14 09:40:53 +00:00
|
|
|
|
import { cancelQuestionDeletion } from "@root/questions/actions";
|
|
|
|
|
import { updateEditSomeQuestion } from "@root/uiTools/actions";
|
2023-12-12 19:05:30 +00:00
|
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
2023-12-14 09:40:53 +00:00
|
|
|
|
import { useUiTools } from "@root/uiTools/store";
|
2023-08-11 07:25:28 +00:00
|
|
|
|
|
2023-09-28 12:33:02 +00:00
|
|
|
|
|
2023-11-14 20:15:52 +00:00
|
|
|
|
type Props = {
|
2023-11-29 13:49:52 +00:00
|
|
|
|
question: AnyTypedQuizQuestion | UntypedQuizQuestion;
|
2023-11-14 20:15:52 +00:00
|
|
|
|
isDragging: boolean;
|
|
|
|
|
index: number;
|
2023-08-11 07:25:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-14 20:15:52 +00:00
|
|
|
|
function DraggableListItem({ question, isDragging, index }: Props) {
|
2023-10-05 14:03:54 +00:00
|
|
|
|
const theme = useTheme();
|
2023-12-14 09:40:53 +00:00
|
|
|
|
const { editSomeQuestion } = useUiTools();
|
2023-12-05 23:34:40 +00:00
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (editSomeQuestion !== null) {
|
|
|
|
|
const setI = setInterval(() => {
|
2023-12-12 19:05:30 +00:00
|
|
|
|
let comp = document.getElementById(editSomeQuestion);
|
|
|
|
|
if (comp !== null) {
|
|
|
|
|
clearInterval(setI);
|
|
|
|
|
comp.scrollIntoView({ behavior: 'instant' });
|
|
|
|
|
updateEditSomeQuestion();
|
|
|
|
|
}
|
|
|
|
|
}, 200);
|
2023-12-05 23:34:40 +00:00
|
|
|
|
|
|
|
|
|
}
|
2023-12-12 19:05:30 +00:00
|
|
|
|
}, [editSomeQuestion]);
|
2023-09-27 14:14:48 +00:00
|
|
|
|
|
2023-10-05 14:03:54 +00:00
|
|
|
|
return (
|
2023-11-14 20:15:52 +00:00
|
|
|
|
<Draggable draggableId={question.id.toString()} index={index}>
|
|
|
|
|
{(provided) => (
|
|
|
|
|
<ListItem
|
|
|
|
|
ref={provided.innerRef}
|
|
|
|
|
{...provided.draggableProps}
|
|
|
|
|
sx={{ userSelect: "none", padding: 0 }}
|
2023-10-05 14:03:54 +00:00
|
|
|
|
>
|
2023-11-17 15:42:49 +00:00
|
|
|
|
{question.deleted ? (
|
2023-11-14 20:15:52 +00:00
|
|
|
|
<Box
|
|
|
|
|
{...provided.dragHandleProps}
|
|
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
maxWidth: "800px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
marginBottom: "40px",
|
|
|
|
|
gap: "5px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Вопрос удалён.
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography
|
2023-12-12 19:05:30 +00:00
|
|
|
|
onClick={() => {
|
|
|
|
|
cancelQuestionDeletion(question.id);
|
2023-11-14 20:15:52 +00:00
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
textDecoration: "underline",
|
|
|
|
|
color: theme.palette.brightPurple.main,
|
|
|
|
|
textDecorationColor: theme.palette.brightPurple.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Восстановить?
|
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
) : (
|
|
|
|
|
<Box sx={{ width: "100%", position: "relative" }}>
|
|
|
|
|
<QuestionsPageCard
|
|
|
|
|
question={question}
|
|
|
|
|
draggableProps={provided.dragHandleProps}
|
|
|
|
|
isDragging={isDragging}
|
2023-11-30 06:27:15 +00:00
|
|
|
|
index={index}
|
2023-11-14 20:15:52 +00:00
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</ListItem>
|
2023-10-05 14:03:54 +00:00
|
|
|
|
)}
|
2023-11-14 20:15:52 +00:00
|
|
|
|
</Draggable>
|
2023-10-05 14:03:54 +00:00
|
|
|
|
);
|
2023-11-14 20:15:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DraggableListItemMemo = memo(DraggableListItem);
|
|
|
|
|
|
|
|
|
|
export default DraggableListItemMemo;
|