fix dragdrop
This commit is contained in:
parent
c6cb130d5b
commit
aa917fe6ba
@ -2,7 +2,11 @@ import { Box } from "@mui/material";
|
||||
import { reorderQuestionVariants } from "@root/questions/actions";
|
||||
import { type ReactNode } from "react";
|
||||
import type { DropResult } from "react-beautiful-dnd";
|
||||
import { DragDropContext, Droppable } from "react-beautiful-dnd";
|
||||
import { DragDropContext as DragDropContextOriginal } from "react-beautiful-dnd";
|
||||
import { StrictModeDroppable } from "./StrictModeDroppable";
|
||||
|
||||
// Исправляем типизацию для DragDropContext
|
||||
const DragDropContext = DragDropContextOriginal as any;
|
||||
|
||||
type AnswerDraggableListProps = {
|
||||
questionId: string;
|
||||
@ -14,21 +18,36 @@ export const AnswerDraggableList = ({
|
||||
variants,
|
||||
}: AnswerDraggableListProps) => {
|
||||
const onDragEnd = ({ destination, source }: DropResult) => {
|
||||
if (destination) {
|
||||
// Проверяем наличие необходимых данных
|
||||
if (!destination || !source) return;
|
||||
|
||||
// Проверяем, что индексы действительно изменились
|
||||
if (destination.index === source.index) return;
|
||||
|
||||
// Проверяем валидность индексов
|
||||
if (source.index < 0 || destination.index < 0) return;
|
||||
|
||||
try {
|
||||
reorderQuestionVariants(questionId, source.index, destination.index);
|
||||
} catch (error) {
|
||||
console.error('Error reordering variants:', error);
|
||||
// Здесь можно добавить уведомление пользователю об ошибке
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<DragDropContext onDragEnd={onDragEnd}>
|
||||
<Droppable droppableId="droppable-answer-list">
|
||||
<StrictModeDroppable droppableId="droppable-answer-list">
|
||||
{(provided) => (
|
||||
<Box ref={provided.innerRef} {...provided.droppableProps}>
|
||||
<Box
|
||||
ref={provided.innerRef}
|
||||
{...provided.droppableProps}
|
||||
>
|
||||
{variants}
|
||||
{provided.placeholder}
|
||||
</Box>
|
||||
)}
|
||||
</Droppable>
|
||||
</StrictModeDroppable>
|
||||
</DragDropContext>
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user