Browse Source

feat: added more details to update event when item is moved within a list in custom draggable

Kristian Vos 2 years ago
parent
commit
797c7da058
1 changed files with 11 additions and 2 deletions
  1. 11 2
      frontend/src/components/Draggable.vue

+ 11 - 2
frontend/src/components/Draggable.vue

@@ -49,7 +49,9 @@ const onDragStart = (itemIndex: number, event: DragEvent) => {
 		itemIndex,
 		itemListName: props.name,
 		itemGroup: props.options.group,
-		itemOnMove
+		itemOnMove,
+		initialItemIndex: itemIndex,
+		initialItemListName: props.name
 	};
 
 	// Emits the start event to the parent component, indicating that dragging has started
@@ -112,7 +114,14 @@ const onDragEnd = () => {
 // Gets called when an element is dropped on another element
 const onDrop = () => {
 	// Emits the update event to parent component, indicating that the order is now done and ordering/moving is done
-	emit("update");
+	const { itemIndex, itemListName, initialItemIndex, initialItemListName } =
+		window.draggingItem;
+	if (itemListName === initialItemListName)
+		emit("update", {
+			moved: { oldIndex: initialItemIndex, newIndex: itemIndex }
+		});
+	else emit("update", {});
+	delete window.draggingItem;
 };
 
 // Function that gets called for each item and returns attributes