frontPanel/src/pages/Questions/DraggableList/DraggableListItem.tsx

98 lines
3.8 KiB
TypeScript
Raw Normal View History

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";
import { memo, useEffect } from "react";
2023-08-11 07:25:28 +00:00
import { Draggable } from "react-beautiful-dnd";
import QuestionsPageCard from "./QuestionPageCard";
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";
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();
const { editSomeQuestion } = useUiTools();
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-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}
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;