[Frontend] Refactor useTaskMonitor Hook: Decompose into WebSocket, NodeState, Payments, and Outputs Hooks - #216
Merged
devJaja merged 1 commit intoJul 29, 2026
Conversation
- Decompose monolithic 228-line useTaskMonitor into 4 focused sub-hooks - Create useTaskWebSocket for WebSocket connection management - Create useNodeState for node state machine and transitions - Create useTaskPayments for payment status tracking - Create useTaskOutputs for output aggregation from completed nodes - Add comprehensive tests for all sub-hooks (53 new tests) - Maintain API compatibility with TaskDetailPage - Remove mock data fallback for production code - Follow Single Responsibility Principle for better maintainability Fixes Epta-Node#167
|
@Clement-coder is attempting to deploy a commit to the Jaja's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Objective
Decompose the monolithic 228-line useTaskMonitor hook into focused, testable sub-hooks following the Single Responsibility Principle.
✅ Changes Made
Files Created
frontend/src/hooks/useTaskWebSocket.ts- WebSocket connection management with exponential backoff reconnectionfrontend/src/hooks/useNodeState.ts- Node state machine handling transitions (pending → running → completed/failed)frontend/src/hooks/useTaskPayments.ts- Payment status tracking per node, payment history, and total cost calculationfrontend/src/hooks/useTaskOutputs.ts- Output aggregation from completed nodes and final merged resultTest Files Created
frontend/src/hooks/useTaskWebSocket.test.ts- WebSocket hook tests (9 tests)frontend/src/hooks/useNodeState.test.ts- Node state hook tests (14 tests)frontend/src/hooks/useTaskPayments.test.ts- Payments hook tests (15 tests)frontend/src/hooks/useTaskOutputs.test.ts- Outputs hook tests (15 tests)Files Modified
frontend/src/hooks/useTaskMonitor.ts- Refactored from 228 lines to ~80 lines by composing the 4 sub-hooks🏗️ Architecture Benefits
🧪 Testing
npm run build- No TypeScript errorsnpm test- All 116 tests pass (53 new tests added)📋 Key Features Implemented
WebSocket Hook (
useTaskWebSocket)Node State Hook (
useNodeState)getNodeStatus,getCompletedNodes,getRunningNodes,getFailedNodesPayments Hook (
useTaskPayments)Outputs Hook (
useTaskOutputs)🔄 Migration
The refactored hook maintains the same public API, so no changes are needed in
TaskDetailPage.tsx. The decomposition is purely internal.Closes #167