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

87 lines
2.7 KiB
TypeScript
Raw Normal View History

2023-09-28 12:33:02 +00:00
import { memo } from "react";
2023-09-27 14:14:48 +00:00
import { useParams } from "react-router-dom";
2023-08-11 07:25:28 +00:00
import { Draggable } from "react-beautiful-dnd";
2023-09-27 14:14:48 +00:00
import { Box, ListItem, Typography, useTheme } from "@mui/material";
2023-08-11 07:25:28 +00:00
import QuestionsPageCard from "./QuestionPageCard";
2023-10-05 14:03:54 +00:00
import { updateQuestionsList } from "@root/questions";
2023-09-27 14:14:48 +00:00
2023-10-05 14:03:54 +00:00
import { QuizQuestionBase } from "../../../model/questionTypes/shared";
2023-09-28 12:33:02 +00:00
2023-08-11 07:25:28 +00:00
type DraggableListItemProps = {
index: number;
2023-09-13 10:58:07 +00:00
isDragging: boolean;
2023-10-05 14:03:54 +00:00
questionData: QuizQuestionBase;
2023-08-11 07:25:28 +00:00
};
2023-10-05 14:03:54 +00:00
export default memo(
({ index, isDragging, questionData }: DraggableListItemProps) => {
const quizId = Number(useParams().quizId);
const theme = useTheme();
console.log("Мой индекс " + index);
console.log(questionData);
2023-09-27 14:14:48 +00:00
2023-10-05 14:03:54 +00:00
return (
<Draggable draggableId={String(index)} index={index}>
{(provided) => (
<ListItem
ref={provided.innerRef}
{...provided.draggableProps}
sx={{ userSelect: "none", padding: 0 }}
>
{questionData.deleted ? (
<Box
{...provided.dragHandleProps}
2023-09-27 14:14:48 +00:00
sx={{
2023-10-05 14:03:54 +00:00
width: "100%",
maxWidth: "800px",
display: "flex",
justifyContent: "center",
marginBottom: "40px",
gap: "5px",
2023-09-27 14:14:48 +00:00
}}
>
2023-10-05 14:03:54 +00:00
<Typography
sx={{
fontSize: "16px",
color: theme.palette.grey2.main,
}}
>
Вопрос удалён.
</Typography>
<Typography
onClick={() => {
updateQuestionsList<QuizQuestionBase>(quizId, index, {
...questionData,
deleted: false,
});
}}
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
key={index}
totalIndex={index}
draggableProps={provided.dragHandleProps}
isDragging={isDragging}
/>
</Box>
)}
</ListItem>
)}
</Draggable>
);
}
2023-08-11 07:25:28 +00:00
);