Commit graph

1 commit

Author SHA1 Message Date
Jan-Henrik Bruhn
c905c4f5f7 refactor: Extract business logic from FileUpload into custom hooks
**Problem:**
FileUpload component mixed UI and business logic making it:
- Hard to test business logic independently
- Difficult to reuse logic elsewhere
- Component had too many responsibilities (550+ lines)
- Harder to understand and maintain

**Solution:**
Extracted business logic into three focused custom hooks:

1. **useFileUpload** (84 lines)
   - File selection and conversion
   - Pyodide initialization handling
   - Error handling

2. **usePatternRotationUpload** (145 lines)
   - Rotation transformation logic
   - PEN encoding/decoding
   - Center shift calculation
   - Upload orchestration

3. **usePatternValidation** (105 lines)
   - Bounds checking logic
   - Rotated pattern validation
   - Error message generation

**Impact:**
- FileUpload component reduced from 550 → 350 lines (36% smaller)
- Business logic now testable in isolation
- Clear separation of concerns
- Logic can be reused in other components
- Improved maintainability

**Technical Details:**
- All hooks fully typed with TypeScript
- Proper dependency management with useCallback/useMemo
- No behavioral changes
- Build tested successfully
- Linter passed

Fixes #39

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-27 11:36:04 +01:00