Skip to content

Commit 39b3081

Browse files
🐛(frontend) Switched to closest center collision strategy
1 parent e76b346 commit 39b3081

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

client/src/components/Board/Board.jsx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import {
44
DndContext,
55
DragOverlay,
6-
closestCorners,
6+
closestCenter,
77
KeyboardSensor,
88
PointerSensor,
99
useSensor,
@@ -72,10 +72,12 @@ function Board({
7272

7373
const [isListAddOpened, setIsListAddOpened] = useState(false);
7474

75+
const listsIds = useMemo(() => listItems.map((list) => list.id), [listItems]);
76+
7577
const sensors = useSensors(
7678
useSensor(PointerSensor, {
7779
activationConstraint: {
78-
distance: 5,
80+
distance: 1,
7981
},
8082
}),
8183
useSensor(KeyboardSensor, {
@@ -107,6 +109,7 @@ function Board({
107109

108110
const handleDragOver = (event) => {
109111
const { active, over } = event;
112+
110113
if (!over) return;
111114

112115
const draggedId = active.id;
@@ -134,16 +137,17 @@ function Board({
134137

135138
// Handle list reordering in real-time
136139
if (isActiveList && isOverList) {
137-
setListItems((currentListItems) => {
138-
const activeIndex = currentListItems.findIndex((col) => col.id === draggedId);
139-
const overIndex = currentListItems.findIndex((col) => col.id === overId);
140-
141-
if (activeIndex !== -1 && overIndex !== -1 && activeIndex !== overIndex) {
142-
return arrayMove(currentListItems, activeIndex, overIndex);
143-
}
144-
return currentListItems;
145-
});
146-
return;
140+
setTimeout(() => {
141+
setListItems((currentListItems) => {
142+
const activeIndex = currentListItems.findIndex((col) => col.id === draggedId);
143+
const overIndex = currentListItems.findIndex((col) => col.id === overId);
144+
145+
if (activeIndex !== -1 && overIndex !== -1 && activeIndex !== overIndex) {
146+
return arrayMove(currentListItems, activeIndex, overIndex);
147+
}
148+
return currentListItems;
149+
});
150+
}, 0);
147151
}
148152

149153
// Skip card logic if dragging a list
@@ -195,6 +199,7 @@ function Board({
195199

196200
const handleDragEnd = (event) => {
197201
const { active, over } = event;
202+
198203
if (!over) {
199204
setActiveId(null);
200205
return;
@@ -307,15 +312,12 @@ function Board({
307312
<div className={styles.wrapper}>
308313
<DndContext
309314
sensors={sensors}
310-
collisionDetection={closestCorners}
315+
collisionDetection={closestCenter}
311316
onDragStart={handleDragStart}
312317
onDragOver={handleDragOver}
313318
onDragEnd={handleDragEnd}
314319
>
315-
<SortableContext
316-
items={listItems.map((col) => col.id)}
317-
strategy={horizontalListSortingStrategy}
318-
>
320+
<SortableContext items={listsIds} strategy={horizontalListSortingStrategy}>
319321
<div className={styles.container}>
320322
{listItems.map((list) => (
321323
<List

client/src/components/Board/Card/Card.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ function Card({
5656
onLabelDelete,
5757
currentUser,
5858
}) {
59-
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
59+
const { setNodeRef, attributes, listeners, transform, transition, isDragging } = useSortable({
6060
id,
61+
data: { type: 'Card', id },
6162
disabled: !canEdit,
6263
});
64+
6365
const style = {
6466
transform: CSS.Transform.toString(transform),
6567
transition,

client/src/components/Board/List/List.jsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useRef, useCallback } from 'react';
1+
import React, { useState, useRef, useCallback, useMemo } from 'react';
22
import PropTypes from 'prop-types';
33

44
import { SortableContext, verticalListSortingStrategy, useSortable } from '@dnd-kit/sortable';
@@ -49,6 +49,7 @@ function List({
4949
}) {
5050
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
5151
id,
52+
data: { type: 'List', id },
5253
disabled: !canEdit,
5354
});
5455

@@ -65,6 +66,10 @@ function List({
6566
transition,
6667
};
6768

69+
const cardsIds = useMemo(() => {
70+
return cards.map((card) => card.id);
71+
}, [cards]);
72+
6873
const nameEdit = useRef(null);
6974

7075
const ListActionsPopover = usePopup(ListActionsStep);
@@ -171,14 +176,8 @@ function List({
171176
</ListActionsPopover>
172177
)}
173178
</div>
174-
<SortableContext items={cards.map((c) => c.id)} strategy={verticalListSortingStrategy}>
175-
<div
176-
ref={setDropRef}
177-
className={classNames(
178-
styles.cardsContainer,
179-
isOver && cards.length === 0 && styles.dropZoneActive,
180-
)}
181-
>
179+
<SortableContext items={cardsIds} strategy={verticalListSortingStrategy}>
180+
<div ref={setDropRef} className={classNames(styles.cardsContainer)}>
182181
{cards.map((card) => (
183182
<Card
184183
key={card.id}

start

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
export NODE_ENV=production && set -e && node db/init.js && node app.js --prod

0 commit comments

Comments
 (0)