refactor(task-drawer): streamline task name handling and enhance socket management
- Removed local socket listener for task name changes, relying on global socket handlers for real-time updates. - Simplified task name change handling logic to improve clarity and maintainability. - Enhanced task status group matching logic in useTaskSocketHandlers for better accuracy with multiple matching strategies. - Added detailed logging for task movement and status changes to aid in debugging and tracking.
This commit is contained in:
@@ -243,10 +243,64 @@ 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 (not UUID)
|
||||
const targetGroup = groups.find(group => group.groupValue === newStatusValue);
|
||||
// Find target group based on new status value with multiple matching strategies
|
||||
let targetGroup = groups.find(group => group.groupValue === newStatusValue);
|
||||
|
||||
// If not found, try case-insensitive matching
|
||||
if (!targetGroup) {
|
||||
targetGroup = groups.find(group =>
|
||||
group.groupValue?.toLowerCase() === newStatusValue.toLowerCase()
|
||||
);
|
||||
}
|
||||
|
||||
// If still not found, try matching with title
|
||||
if (!targetGroup) {
|
||||
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')
|
||||
);
|
||||
}
|
||||
|
||||
console.log('🔄 Status change group movement debug:', {
|
||||
taskId: response.id,
|
||||
newStatusValue,
|
||||
currentGroupId: currentGroup?.id,
|
||||
currentGroupValue: currentGroup?.groupValue,
|
||||
currentGroupTitle: currentGroup?.title,
|
||||
targetGroupId: targetGroup?.id,
|
||||
targetGroupValue: targetGroup?.groupValue,
|
||||
targetGroupTitle: targetGroup?.title,
|
||||
allGroups: groups.map(g => ({ id: g.id, title: g.title, groupValue: g.groupValue }))
|
||||
});
|
||||
|
||||
if (currentGroup && targetGroup && currentGroup.id !== targetGroup.id) {
|
||||
console.log('✅ Moving task between groups:', {
|
||||
from: currentGroup.title,
|
||||
to: targetGroup.title
|
||||
});
|
||||
// Use the action to move task between groups
|
||||
dispatch(
|
||||
moveTaskBetweenGroups({
|
||||
@@ -255,8 +309,12 @@ export const useTaskSocketHandlers = () => {
|
||||
targetGroupId: targetGroup.id,
|
||||
})
|
||||
);
|
||||
} 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 for status change');
|
||||
console.log('🔧 No group movement needed - task already in correct group');
|
||||
}
|
||||
} else {
|
||||
console.log('🔧 Not grouped by status, skipping group movement');
|
||||
@@ -628,7 +686,21 @@ export const useTaskSocketHandlers = () => {
|
||||
const handleTaskDescriptionChange = useCallback(
|
||||
(data: { id: string; parent_task: string; description: string }) => {
|
||||
if (!data) return;
|
||||
|
||||
// Update the old task slice (for backward compatibility)
|
||||
dispatch(updateTaskDescription(data));
|
||||
|
||||
// Update task-management slice for task-list-v2 components
|
||||
const currentTask = store.getState().taskManagement.entities[data.id];
|
||||
if (currentTask) {
|
||||
const updatedTask: Task = {
|
||||
...currentTask,
|
||||
description: data.description,
|
||||
updatedAt: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString(),
|
||||
};
|
||||
dispatch(updateTask(updatedTask));
|
||||
}
|
||||
},
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user