Successfully reduced App.tsx from 3,299 lines to 2,685 lines (18.6% reduction) by extracting logic into dedicated services, components, and hooks.
File: services/generationService.ts
Lines Saved: ~519
Status: Fully Integrated
The generateSingleItem function was moved from App.tsx to GenerationService, eliminating code duplication.
File: components/DeepPhaseConfigPanel.tsx
Lines Saved: ~69
Status: Fully Integrated
The renderDeepPhaseConfig function was extracted into a reusable React component.
File: services/ollamaService.ts
Lines Saved: ~2
Status: Fully Integrated
Consolidated Ollama-related logic into a dedicated service with cleaner API.
File: services/deepConfigService.ts
Lines Saved: ~25
Status: Fully Integrated
Pure functions for deep configuration management (immutable updates).
File: hooks/useHuggingFaceData.ts
Lines: ~290
Status: Created, ready for integration
Manages:
- HuggingFace dataset configuration
- Dataset search and selection
- Column detection and prefetching
- Preview data loading
To Integrate:
-
Remove HF state declarations (lines ~194-240 in App.tsx):
- hfConfig, setHfConfig
- hfStructure, setHfStructure
- hfSearchResults, setHfSearchResults
- isSearchingHF, setIsSearchingHF
- showHFResults, setShowHFResults
- availableColumns, setAvailableColumns
- detectedColumns, setDetectedColumns
- isPrefetching, setIsPrefetching
- hfPreviewData, setHfPreviewData
- hfTotalRows, setHfTotalRows
- isLoadingHfPreview, setIsLoadingHfPreview
- searchTimeoutRef
-
Remove HF handler functions (lines ~502-654):
- prefetchColumns
- handleHFSearch
- handleSelectHFDataset
- handleConfigChange
- handleSplitChange
- handleDataSourceModeChange
-
Add hook usage:
const hfData = useHuggingFaceData(setError);- Replace all references to HF state with
hfData.hfConfig,hfData.hfStructure, etc.
File: hooks/useSessionManagement.ts
Lines: ~290
Status: Created, ready for integration
Manages:
- Session configuration building
- Save/load sessions (local files)
- Cloud save/load/delete operations
- Starting new sessions
- Restoring sessions
To Integrate:
-
Remove session management state (lines ~221-224):
- showCloudLoadModal, setShowCloudLoadModal
- cloudSessions, setCloudSessions
- isCloudLoading, setIsCloudLoading
-
Remove session handler functions (lines ~808-1107):
- buildSessionConfig
- getSessionData
- restoreSession
- handleSaveSession
- handleLoadSession
- handleCloudSave
- handleCloudLoadOpen
- handleCloudSessionSelect
- handleCloudSessionDelete
- startNewSession
-
Add hook usage:
const sessionMgmt = useSessionManagement(
{ /* current state values */ },
{ /* setters */ },
{ /* state setters */ }
);- App.tsx: 2,685 lines (down from 3,299)
- Build Status: ✅ Passing
- TypeScript: ✅ No new errors introduced
components/
└── DeepPhaseConfigPanel.tsx (152 lines)
services/
├── ollamaService.ts (95 lines)
└── deepConfigService.ts (115 lines)
hooks/
├── useHuggingFaceData.ts (290 lines)
└── useSessionManagement.ts (290 lines)
- Better Separation of Concerns: Logic is organized by domain
- Improved Testability: Services and hooks can be unit tested independently
- Code Reusability: Components and hooks can be reused across the app
- Maintainability: Smaller, focused files are easier to understand and modify
- Type Safety: All extractions maintain full TypeScript type safety
To complete the integration:
-
Integrate useHuggingFaceData:
- Replace HF state with hook
- Update all HF-related JSX to use hook values
- Test dataset loading, search, and column detection
-
Integrate useSessionManagement:
- Replace session handlers with hook
- Update save/load UI to use hook methods
- Test session persistence and cloud sync
-
Future Extractions (Optional):
- Extract streaming logic to
useStreaming - Extract log management to
useLogManagement - Extract generation control to
useGeneration
- Extract streaming logic to
After each integration:
- TypeScript compilation passes
- Build succeeds
- All existing functionality works
- No console errors
- HF dataset loading works
- Session save/load works
- Cloud sync works (if configured)
When integrating hooks:
- Start with one hook at a time
- Keep the old code commented out initially
- Test thoroughly before removing old code
- Use TypeScript errors as a guide for what needs updating
- Check all references to moved state/functions
- All hooks follow React best practices (useCallback, proper dependencies)
- Services use pure functions where possible
- Type safety maintained throughout
- No breaking changes to existing functionality
- Build size remains similar (better code organization, not code elimination)