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:
shancds
2025-06-17 16:46:36 +05:30
parent 4dbaab060a
commit 0e0d1a5f11

View File

@@ -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.');
@@ -379,7 +376,7 @@ const ProjectViewBoard = () => {
}; };
// logger.error('Emitting socket event with payload (task not found in source):', body); // logger.error('Emitting socket event with payload (task not found in source):', body);
// 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);
@@ -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);
} }