2.5 KiB
2.5 KiB
Refactor Plan: SkillsTab.tsx
Current State
- File:
src/components/game/tabs/SkillsTab.tsx - Lines: 434
- Target: ≤400 lines (reduce by ~34 lines)
Proposed File Structure
1. src/lib/game/utils.ts (NEW, ≈20 lines)
Contains:
formatStudyTimefunction
Rationale: Simple pure utility function, zero-risk extraction.
2. src/components/game/tabs/SkillUpgradeDialog.tsx (NEW, ≈80 lines)
Contains:
SkillUpgradeDialogcomponent (extracted fromrenderUpgradeDialog)- Dialog UI and selection state handlers
Rationale: Isolates the upgrade dialog UI (~100 lines worth from parent), simplifies SkillsTab significantly. Uses callback props.
3. src/components/game/SkillRow.tsx (NEW, ≈100 lines)
Contains:
SkillRowcomponent for individual skill rows- Level dots, buttons, study toggle, tier-up, milestone badges
Rationale: Encapsulates per-skill UI (~150 lines worth from parent), reusable, simplifies SkillsTab.
4. src/lib/game/hooks/useSkillUpgradeSelection.ts (NEW, ≈40 lines)
Contains:
useSkillUpgradeSelectioncustom hook- Selection state and mutation logic for milestone upgrades
Rationale: Encapsulates upgrade selection logic previously inline in SkillsTab.
5. src/components/game/tabs/SkillsTab.tsx (≈150 lines)
Keeps:
- Core
SkillsTabcomponent shell - Category-level layout
- Main store hook calls
- Tab switching
Rationale: Maintains coordination role while delegating details to extracted components/hooks.
Circular Import Risks
MEDIUM RISK:
SkillRowneeds access to many store selectors and actions. May accept callbacks as props to avoid direct store access (kept in parent).SkillUpgradeDialogneeds data from store; will receive computed values as props.useSkillUpgradeSelectionneedsSKILL_EVOLUTION_PATHSand store commits - safe.
MITIGATION:
- Keep store interactions in
SkillsTab, pass data down via props. - Accept slight prop drilling vs. direct store access in extracted components for cleaner boundaries.
Extraction Order
1 → 4 → 3 → 2 → 5
- Create
utils.ts, moveformatStudyTime, update SkillsTab import. - Create
useSkillUpgradeSelectionhook, move selection logic, update SkillsTab. - Create
SkillRow, move per-skill UI (pass callbacks from parent), update SkillsTab. - Create
SkillUpgradeDialog, move dialog UI, update SkillsTab. - Delete old extracted sections from SkillsTab, verify ≤400 lines.