refactor(project-view-board): clean up code and improve task handling logic
- Removed unnecessary conditional checks and whitespace for better readability. - Streamlined task movement logic to enhance performance during drag-and-drop operations. - Improved socket event emission for task sort order changes, ensuring more reliable updates. - Cleaned up comments and organized code structure for clarity.
This commit is contained in:
@@ -245,7 +245,6 @@ const ProjectViewBoard = () => {
|
|||||||
if (
|
if (
|
||||||
activeGroupId &&
|
activeGroupId &&
|
||||||
overGroupId &&
|
overGroupId &&
|
||||||
activeGroupId !== overGroupId &&
|
|
||||||
active.data.current?.type === 'task'
|
active.data.current?.type === 'task'
|
||||||
) {
|
) {
|
||||||
// Find the target index in the over group
|
// Find the target index in the over group
|
||||||
@@ -260,7 +259,6 @@ const ProjectViewBoard = () => {
|
|||||||
targetIndex = targetGroup.tasks.length;
|
targetIndex = targetGroup.tasks.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use debounced move task to prevent rapid updates
|
// Use debounced move task to prevent rapid updates
|
||||||
debouncedMoveTask(
|
debouncedMoveTask(
|
||||||
activeId as string,
|
activeId as string,
|
||||||
@@ -342,7 +340,6 @@ const ProjectViewBoard = () => {
|
|||||||
|
|
||||||
// Find indices
|
// Find indices
|
||||||
let fromIndex = sourceGroup.tasks.findIndex(t => t.id === task.id);
|
let fromIndex = sourceGroup.tasks.findIndex(t => t.id === task.id);
|
||||||
|
|
||||||
// Handle case where task is not found in source group (might have been moved already in UI)
|
// Handle case where task is not found in source group (might have been moved already in UI)
|
||||||
if (fromIndex === -1) {
|
if (fromIndex === -1) {
|
||||||
logger.info('Task not found in source group. Using task sort_order from task object.');
|
logger.info('Task not found in source group. Using task sort_order from task object.');
|
||||||
@@ -416,7 +413,6 @@ const ProjectViewBoard = () => {
|
|||||||
const toPos = targetGroup.tasks[toIndex]?.sort_order ||
|
const toPos = targetGroup.tasks[toIndex]?.sort_order ||
|
||||||
targetGroup.tasks[targetGroup.tasks.length - 1]?.sort_order ||
|
targetGroup.tasks[targetGroup.tasks.length - 1]?.sort_order ||
|
||||||
-1;
|
-1;
|
||||||
|
|
||||||
// Prepare socket event payload
|
// Prepare socket event payload
|
||||||
const body = {
|
const body = {
|
||||||
project_id: projectId,
|
project_id: projectId,
|
||||||
@@ -429,7 +425,6 @@ const ProjectViewBoard = () => {
|
|||||||
task,
|
task,
|
||||||
team_id: currentSession?.team_id
|
team_id: currentSession?.team_id
|
||||||
};
|
};
|
||||||
|
|
||||||
// Emit socket event
|
// Emit socket event
|
||||||
if (socket) {
|
if (socket) {
|
||||||
socket.emit(SocketEvents.TASK_SORT_ORDER_CHANGE.toString(), body);
|
socket.emit(SocketEvents.TASK_SORT_ORDER_CHANGE.toString(), body);
|
||||||
@@ -443,7 +438,6 @@ const ProjectViewBoard = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track analytics event
|
// Track analytics event
|
||||||
trackMixpanelEvent(evt_project_task_list_drag_and_move);
|
trackMixpanelEvent(evt_project_task_list_drag_and_move);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user