2023-08-11 07:25:28 +00:00
|
|
|
import { Box } from "@mui/material";
|
2023-11-29 13:49:52 +00:00
|
|
|
import { reorderQuestions } from "@root/questions/actions";
|
2023-11-16 16:41:25 +00:00
|
|
|
import type { DropResult } from "react-beautiful-dnd";
|
|
|
|
import { DragDropContext, Droppable } from "react-beautiful-dnd";
|
|
|
|
import DraggableListItem from "./DraggableListItem";
|
2023-12-07 22:56:31 +00:00
|
|
|
import { useQuestionsStore } from "@root/questions/store";
|
2023-08-11 07:25:28 +00:00
|
|
|
|
|
|
|
|
2023-11-14 20:15:52 +00:00
|
|
|
export const DraggableList = () => {
|
2023-12-07 22:56:31 +00:00
|
|
|
const { questions } = useQuestionsStore()
|
|
|
|
const filteredQuestions = questions.filter((question) => question.type !== "result")
|
2023-11-16 16:41:25 +00:00
|
|
|
const onDragEnd = ({ destination, source }: DropResult) => {
|
|
|
|
if (destination) reorderQuestions(source.index, destination.index);
|
2023-11-14 20:15:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DragDropContext onDragEnd={onDragEnd}>
|
|
|
|
<Droppable droppableId="droppable-list">
|
|
|
|
{(provided, snapshot) => (
|
|
|
|
<Box ref={provided.innerRef} {...provided.droppableProps}>
|
2023-12-07 22:56:31 +00:00
|
|
|
{filteredQuestions.map((question, index) => (
|
2023-11-14 20:15:52 +00:00
|
|
|
<DraggableListItem
|
2023-11-27 23:07:24 +00:00
|
|
|
key={question.id}
|
2023-11-14 20:15:52 +00:00
|
|
|
question={question}
|
|
|
|
isDragging={snapshot.isDraggingOver}
|
|
|
|
index={index}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
{provided.placeholder}
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</Droppable>
|
|
|
|
</DragDropContext>
|
|
|
|
);
|
2023-08-11 07:25:28 +00:00
|
|
|
};
|