Skip to content

Commit

Permalink
progress report/bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mridun-gupta committed Aug 30, 2024
1 parent 95b5670 commit 2feda2e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
47 changes: 47 additions & 0 deletions js/view/dropzone.js
Original file line number Diff line number Diff line change
@@ -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(`
<div class="dropzone"></div>
`).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;
}
}
47 changes: 0 additions & 47 deletions js/view/kanban.js
Original file line number Diff line number Diff line change
@@ -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(`
<div class="dropzone"></div>
`).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;
}
}

0 comments on commit 2feda2e

Please sign in to comment.