4.1 KiB
4.1 KiB
State Management Consolidation Plan
Problem Analysis
Current Mess
The codebase has multiple competing state management solutions causing confusion and redundancy:
1. /apps/website/components/shared/state/ (The "New" Solution)
- StateContainer.tsx - Combined wrapper for all states (loading, error, empty, success)
- LoadingWrapper.tsx - 5 variants: spinner, skeleton, full-screen, inline, card
- ErrorDisplay.tsx - 4 variants: full-screen, inline, card, toast
- EmptyState.tsx - 3 variants + pre-configured states + illustrations
- ❌ Missing types file:
../types/state.types(deleted but still imported)
2. /apps/website/components/shared/ (Legacy Simple Components)
- EmptyState.tsx - Simple empty state (39 lines)
- LoadingState.tsx - Simple loading spinner (15 lines)
3. /apps/website/components/errors/ (Alternative Error Solutions)
- ErrorDisplay.tsx - API error focused (different API than shared/state)
- EnhancedErrorBoundary.tsx - React error boundary
- ApiErrorBoundary.tsx - API error boundary
- EnhancedFormError.tsx - Form error handling
4. Domain-Specific Solutions
- FeedEmptyState.tsx - Feed-specific empty state
- EmptyState.tsx in leagues - Different design system
Core Issues
- Missing types file causing import errors in all state components
- Multiple similar components with different APIs
- Inconsistent naming patterns
- Redundant functionality
- No single source of truth
- Mixed concerns between generic and domain-specific
Solution Strategy
Phase 1: Create Unified Types
Create apps/website/components/shared/state/types.ts with all type definitions:
- EmptyState types
- LoadingState types
- ErrorDisplay types
- StateContainer types
- Convenience prop types
Phase 2: Consolidate Components
Keep only the comprehensive solution in /apps/website/components/shared/state/:
- Update imports to use new types file
- Ensure all components work with unified types
- Remove any redundant internal type definitions
Phase 3: Remove Redundant Files
Delete:
/apps/website/components/shared/EmptyState.tsx(legacy)/apps/website/components/shared/LoadingState.tsx(legacy)- Keep domain-specific ones if they serve unique purposes
Phase 4: Update All Imports
Find and update all imports across the codebase to use the consolidated solution.
Detailed Implementation
Step 1: Create Types File
File: apps/website/components/shared/state/types.ts
// All type definitions for state management
// EmptyState, LoadingWrapper, ErrorDisplay, StateContainer props
// Plus convenience types
Step 2: Update State Components
Files to update:
EmptyState.tsx- Import from./types.tsLoadingWrapper.tsx- Import from./types.tsErrorDisplay.tsx- Import from./types.tsStateContainer.tsx- Import from./types.ts
Step 3: Remove Legacy Files
Delete:
apps/website/components/shared/EmptyState.tsxapps/website/components/shared/LoadingState.tsx
Step 4: Update External Imports
Search for: from '@/components/shared/EmptyState' or from '@/components/shared/LoadingState'
Replace with: from '@/components/shared/state/EmptyState' or from '@/components/shared/state/LoadingWrapper'
Files to Modify
Create:
apps/website/components/shared/state/types.ts
Update:
apps/website/components/shared/state/EmptyState.tsxapps/website/components/shared/state/LoadingWrapper.tsxapps/website/components/shared/state/ErrorDisplay.tsxapps/website/components/shared/state/StateContainer.tsx
Delete:
apps/website/components/shared/EmptyState.tsxapps/website/components/shared/LoadingState.tsx
Update Imports in:
- Multiple app pages and templates
- Components that use the old paths
Expected Benefits
- ✅ Single source of truth for state types
- ✅ Consistent API across all state components
- ✅ No import errors
- ✅ Reduced file count and complexity
- ✅ Better maintainability
- ✅ Clear separation between generic and domain-specific solutions