Skip to content

Commit 4a45f83

Browse files
committed
fix: keep projects board grid stable during drag
1 parent 725c21b commit 4a45f83

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

client/projects-board.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ProjectsBoardUI {
1919
this.dragSourceColumnId = null;
2020
this.dragCardEl = null;
2121
this.dragPlaceholderEl = null;
22+
this.dragDropInFlight = false;
2223
this._dragOverRaf = null;
2324
this._pendingDragOver = null;
2425
this.hideForks = false;
@@ -604,17 +605,33 @@ class ProjectsBoardUI {
604605
this.dragProjectKey = key;
605606
this.dragSourceColumnId = this.getProjectColumn(key);
606607
this.dragCardEl = card;
608+
this.dragDropInFlight = false;
607609
card.classList.add('dragging');
608-
this.ensureDragPlaceholder(card);
610+
const placeholder = this.ensureDragPlaceholder(card);
611+
const sourceDropzone = card.closest?.('.projects-board-column-body[data-dropzone="true"]') || null;
612+
if (sourceDropzone && placeholder) {
613+
try {
614+
sourceDropzone.insertBefore(placeholder, card);
615+
} catch {}
616+
}
609617
try {
610618
event.dataTransfer?.setData?.('text/plain', key);
611619
event.dataTransfer.effectAllowed = 'move';
612620
} catch {}
621+
622+
// Hide the dragged card from the grid layout so the placeholder doesn't create an extra
623+
// "half column" by adding one more grid item.
624+
setTimeout(() => {
625+
if (card.classList.contains('dragging')) card.classList.add('drag-hidden');
626+
}, 0);
613627
}
614628

615629
onDragEnd(event) {
616630
const card = event.target?.closest?.('.projects-board-card');
617631
if (card) card.classList.remove('dragging');
632+
if (card && !this.dragDropInFlight) {
633+
card.classList.remove('drag-hidden');
634+
}
618635
document.querySelectorAll('.projects-board-column.drag-over').forEach((el) => el.classList.remove('drag-over'));
619636
this.dragProjectKey = null;
620637
this.dragSourceColumnId = null;
@@ -676,6 +693,9 @@ class ProjectsBoardUI {
676693
this.dragSourceColumnId = null;
677694
if (!projectKey || !columnId) return;
678695

696+
const draggedEl = this.dragCardEl;
697+
this.dragDropInFlight = true;
698+
679699
let insertIndex = null;
680700
const dropzone = col.classList.contains('is-collapsed') ? null : this.getColumnDropzone(col);
681701
if (dropzone) {
@@ -718,7 +738,10 @@ class ProjectsBoardUI {
718738
} catch {}
719739
this.render();
720740
} catch (error) {
741+
if (draggedEl) draggedEl.classList.remove('drag-hidden');
721742
this.orchestrator?.showToast?.(String(error?.message || error), 'error');
743+
} finally {
744+
this.dragDropInFlight = false;
722745
}
723746
}
724747

client/styles/projects-board.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@
224224
opacity: 0.65;
225225
}
226226

227+
.projects-board-card.drag-hidden {
228+
display: none;
229+
}
230+
227231
.projects-board-drop-placeholder {
228232
border: 2px dashed rgba(79, 70, 229, 0.55);
229233
border-radius: var(--radius-sm);

0 commit comments

Comments
 (0)