feat(task-status-dropdown): enhance task status update and group movement handling
- Added logic to optimistically update task status in Redux for immediate feedback. - Implemented group movement handling when tasks are updated based on their status, ensuring tasks are moved between groups as needed. - Improved socket event emissions for real-time updates, including parent task handling. - Refactored group selection logic to streamline target group identification based on status ID and group value.
This commit is contained in:
@@ -244,44 +244,18 @@ export const useTaskSocketHandlers = () => {
|
||||
// Find current group containing the task
|
||||
const currentGroup = groups.find(group => group.taskIds.includes(response.id));
|
||||
|
||||
// Find target group based on new status value with multiple matching strategies
|
||||
let targetGroup = groups.find(group => group.groupValue === newStatusValue);
|
||||
// Find target group based on the actual status ID from response
|
||||
let targetGroup = groups.find(group => group.id === response.status_id);
|
||||
|
||||
// If not found, try case-insensitive matching
|
||||
// If not found by status ID, try matching with group value
|
||||
if (!targetGroup) {
|
||||
targetGroup = groups.find(group =>
|
||||
group.groupValue?.toLowerCase() === newStatusValue.toLowerCase()
|
||||
);
|
||||
targetGroup = groups.find(group => group.groupValue === response.status_id);
|
||||
}
|
||||
|
||||
// If still not found, try matching with title
|
||||
if (!targetGroup) {
|
||||
// If still not found, try matching by status name (fallback)
|
||||
if (!targetGroup && response.status) {
|
||||
targetGroup = groups.find(group =>
|
||||
group.title?.toLowerCase() === newStatusValue.toLowerCase()
|
||||
);
|
||||
}
|
||||
|
||||
// If still not found, try matching common status patterns
|
||||
if (!targetGroup && newStatusValue === 'todo') {
|
||||
targetGroup = groups.find(group =>
|
||||
group.title?.toLowerCase().includes('todo') ||
|
||||
group.title?.toLowerCase().includes('to do') ||
|
||||
group.title?.toLowerCase().includes('pending') ||
|
||||
group.groupValue?.toLowerCase().includes('todo')
|
||||
);
|
||||
} else if (!targetGroup && newStatusValue === 'doing') {
|
||||
targetGroup = groups.find(group =>
|
||||
group.title?.toLowerCase().includes('doing') ||
|
||||
group.title?.toLowerCase().includes('progress') ||
|
||||
group.title?.toLowerCase().includes('active') ||
|
||||
group.groupValue?.toLowerCase().includes('doing')
|
||||
);
|
||||
} else if (!targetGroup && newStatusValue === 'done') {
|
||||
targetGroup = groups.find(group =>
|
||||
group.title?.toLowerCase().includes('done') ||
|
||||
group.title?.toLowerCase().includes('complete') ||
|
||||
group.title?.toLowerCase().includes('finish') ||
|
||||
group.groupValue?.toLowerCase().includes('done')
|
||||
group.title?.toLowerCase() === response.status.toLowerCase()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -295,14 +269,11 @@ export const useTaskSocketHandlers = () => {
|
||||
})
|
||||
);
|
||||
} else if (!targetGroup) {
|
||||
console.log('❌ Target group not found for status:', newStatusValue);
|
||||
} else if (!currentGroup) {
|
||||
console.log('❌ Current group not found for task:', response.id);
|
||||
} else {
|
||||
console.log('🔧 No group movement needed - task already in correct group');
|
||||
// Fallback: refetch tasks to ensure consistency
|
||||
if (projectId) {
|
||||
dispatch(fetchTasksV3(projectId));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('🔧 Not grouped by status, skipping group movement');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user