From 2feda2ea4e4eb9f37d0f7208338cb4b5d96fade7 Mon Sep 17 00:00:00 2001 From: Mridun Gupta Date: Fri, 30 Aug 2024 17:36:34 +0530 Subject: [PATCH] progress report/bug fix --- js/view/dropzone.js | 47 +++++++++++++++++++++++++++++++++++++++++++++ js/view/kanban.js | 47 --------------------------------------------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/js/view/dropzone.js b/js/view/dropzone.js index e69de29..ef777c0 100644 --- a/js/view/dropzone.js +++ b/js/view/dropzone.js @@ -0,0 +1,47 @@ +import KanbanAPI from "../api/KanbanAPI.js"; + +export default class DropZone { + static createDropZone() { + const range = document.createRange(); + + range.selectNode(document.body); + + const dropZone = range.createContextualFragment(` +
+ `).children[0]; + + dropZone.addEventListener("dragover", e => { + e.preventDefault(); + dropZone.classList.add("dropzone-active"); + }); + + dropZone.addEventListener("dragleave", () => { + dropZone.classList.remove("dropzone-active"); + }); + + dropZone.addEventListener("drop", e => { + e.preventDefault(); + dropZone.classList.remove("dropzone-active"); + + const columnElement = dropZone.closest(".columns"); + const columnId = Number(columnElement.dataset.id); + const dropZonesInColumn = Array.from(columnElement.querySelectorAll(".dropzone")); + const droppedIndex = dropZonesInColumn.indexOf(dropZone); + const itemId = Number(e.dataTransfer.getData("text/plain")); + const droppedItemElement = document.querySelector(`[data-id="${itemId}"]`); + const insertAfter = dropZone.parentElement.classList.contains("items") ? dropZone.parentElement : dropZone; + + if (droppedItemElement.contains(dropZone)) { + return; + } + + insertAfter.after(droppedItemElement); + KanbanAPI.updateItem(itemId, { + columnId, + position: droppedIndex + }); + }); + + return dropZone; + } +} \ No newline at end of file diff --git a/js/view/kanban.js b/js/view/kanban.js index ef777c0..e69de29 100644 --- a/js/view/kanban.js +++ b/js/view/kanban.js @@ -1,47 +0,0 @@ -import KanbanAPI from "../api/KanbanAPI.js"; - -export default class DropZone { - static createDropZone() { - const range = document.createRange(); - - range.selectNode(document.body); - - const dropZone = range.createContextualFragment(` -
- `).children[0]; - - dropZone.addEventListener("dragover", e => { - e.preventDefault(); - dropZone.classList.add("dropzone-active"); - }); - - dropZone.addEventListener("dragleave", () => { - dropZone.classList.remove("dropzone-active"); - }); - - dropZone.addEventListener("drop", e => { - e.preventDefault(); - dropZone.classList.remove("dropzone-active"); - - const columnElement = dropZone.closest(".columns"); - const columnId = Number(columnElement.dataset.id); - const dropZonesInColumn = Array.from(columnElement.querySelectorAll(".dropzone")); - const droppedIndex = dropZonesInColumn.indexOf(dropZone); - const itemId = Number(e.dataTransfer.getData("text/plain")); - const droppedItemElement = document.querySelector(`[data-id="${itemId}"]`); - const insertAfter = dropZone.parentElement.classList.contains("items") ? dropZone.parentElement : dropZone; - - if (droppedItemElement.contains(dropZone)) { - return; - } - - insertAfter.after(droppedItemElement); - KanbanAPI.updateItem(itemId, { - columnId, - position: droppedIndex - }); - }); - - return dropZone; - } -} \ No newline at end of file