From 6448d24e2036a576c2e9e70db37c076464b655f7 Mon Sep 17 00:00:00 2001 From: chamiakJ Date: Thu, 10 Jul 2025 12:00:56 +0530 Subject: [PATCH] refactor(task-list): simplify subtask handling in AddSubtaskRow and TaskRowWithSubtasks - Updated AddSubtaskRow to remove rowId dependency from onSubtaskAdded and onActivate callbacks, streamlining the subtask addition process. - Enhanced input handling to maintain focus and visibility after adding a subtask. - Refactored TaskRowWithSubtasks to consolidate add subtask row management, ensuring a single add subtask row is displayed when not loading. --- .../task-list-v2/TaskRowWithSubtasks.tsx | 103 ++++++++---------- .../task-list-v2/components/AddTaskRow.tsx | 2 +- 2 files changed, 45 insertions(+), 60 deletions(-) diff --git a/worklenz-frontend/src/components/task-list-v2/TaskRowWithSubtasks.tsx b/worklenz-frontend/src/components/task-list-v2/TaskRowWithSubtasks.tsx index e38c0b72..10226d03 100644 --- a/worklenz-frontend/src/components/task-list-v2/TaskRowWithSubtasks.tsx +++ b/worklenz-frontend/src/components/task-list-v2/TaskRowWithSubtasks.tsx @@ -32,11 +32,11 @@ interface AddSubtaskRowProps { width: string; isSticky?: boolean; }>; - onSubtaskAdded: (rowId: string) => void; + onSubtaskAdded: () => void; // Simplified - no rowId needed rowId: string; // Unique identifier for this add subtask row autoFocus?: boolean; // Whether this row should auto-focus on mount isActive?: boolean; // Whether this row should show the input/button - onActivate?: (rowId: string) => void; // Callback when row becomes active + onActivate?: () => void; // Simplified - no rowId needed } const AddSubtaskRow: React.FC = memo(({ @@ -93,17 +93,31 @@ const AddSubtaskRow: React.FC = memo(({ ); } + // Clear the input but keep it focused for the next subtask setSubtaskName(''); - // Keep the input active and notify parent to create new row - onSubtaskAdded(rowId); - }, [subtaskName, dispatch, parentTaskId, projectId, connected, socket, currentSession, onSubtaskAdded, rowId]); + // Keep isAdding as true so the input stays visible + // Focus the input again after a short delay to ensure it's ready + setTimeout(() => { + if (inputRef.current) { + inputRef.current.focus(); + } + }, 50); + + // Notify parent that subtask was added + onSubtaskAdded(); + }, [subtaskName, dispatch, parentTaskId, projectId, connected, socket, currentSession, onSubtaskAdded]); const handleCancel = useCallback(() => { + setSubtaskName(''); + setIsAdding(false); + }, []); + + const handleBlur = useCallback(() => { + // Only cancel if the input is empty, otherwise keep it active if (subtaskName.trim() === '') { - setSubtaskName(''); - setIsAdding(false); + handleCancel(); } - }, [subtaskName]); + }, [subtaskName, handleCancel]); const handleKeyDown = useCallback((e: React.KeyboardEvent) => { if (e.key === 'Escape') { @@ -135,7 +149,9 @@ const AddSubtaskRow: React.FC = memo(({ !isAdding ? (