Files
orangecat/docs/development/dashboard-analysis.md
T
Your NameandClaude 2b642247b6 fix(profile): fix creator display and redesign Bitcoin donations section
## Profile Display Fix
- Fixed profile creator info showing "Anonymous" instead of display name
- Updated API routes to use correct `display_name` column instead of `name`
- Updated all frontend code (41 replacements across 8 files) to use display_name
- Added database migration for foreign key relationship between projects and profiles

## Gallery UI Improvements
- Redesigned gallery lightbox to be more compact and elegant
- Constrained lightbox images to max-w-5xl and max-h-[85vh] (was full screen)
- Improved main gallery thumbnail sizing and aspect ratios
- Added proper responsive padding and smoother transitions
- Better click handling to prevent accidental closes

## Bitcoin Donations Redesign
- Created new compact BitcoinDonationCard component
- Created BitcoinWalletStatsCompact component without external links
- Removed all mempool.space links per requirements
- Made QR codes always visible with improved layout
- Added "Send with Wallet" button for one-click Bitcoin URI
- Reduced donation section size by ~50% while maintaining functionality
- Modular, DRY code structure for better maintainability

Files changed:
- API: projects/[id]/route.ts, projects/route.ts
- Components: 2 new Bitcoin components, updated profile layout
- Frontend: 8 files updated with display_name references
- Gallery: ProjectMediaGallery.tsx redesigned

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-07 00:14:27 +01:00

692 lines
16 KiB
Markdown

# Dashboard Page - Comprehensive Analysis
**Created:** 2025-11-02
**Last Modified:** 2025-01-30
**Last Modified Summary:** Updated route references to reflect consolidation to /projects/[id]
## 🔴 CRITICAL ERRORS & ISSUES
### 1. **Type Mismatch: Currency Type Definition** ❌ CRITICAL
**Location:** `src/types/funding.ts:23`
**Problem:**
```typescript
currency?: 'BTC' | 'SATS' // Type only allows BTC/SATS
```
But dashboard code uses:
```typescript
currency={project.currency || 'CHF'} // Trying to use CHF
currency={featuredProject.currency || 'CHF'} // Trying to use CHF
```
**Impact:**
- TypeScript errors (type mismatch)
- Runtime could fail if currency is 'CHF'/'USD'/'EUR'
- Type system doesn't match actual database schema
- Database schema supports: 'CHF', 'USD', 'EUR', 'BTC', 'SATS'
**Fix Required:**
```typescript
// src/types/funding.ts
currency?: 'BTC' | 'SATS' | 'CHF' | 'USD' | 'EUR' | string
```
---
### 2. **Missing Currency Field in Project Store** ⚠️
**Location:** `src/stores/projectStore.ts:77-90`
**Problem:**
The project store mapping doesn't explicitly preserve the `currency` field:
```typescript
const projects: Project[] = (data || []).map((project: any) => ({
...project, // Currency should be here but not guaranteed
total_funding: project.raised_amount ?? project.total_funding ?? 0,
// ... but no explicit currency mapping
}));
```
**Issue:**
- Spread operator `...project` should include currency, but:
- Type system doesn't enforce it
- If database field is missing, it won't be in the object
- No default value set
**Recommendation:**
```typescript
currency: project.currency || 'CHF', // Explicit default
```
---
### 3. **Potential Division by Zero** ⚠️
**Location:** Line 574
**Code:**
```typescript
amount={activeProjectsCount > 0 ? totalRaised / activeProjectsCount : 0}
```
**Issue:**
- Protected with ternary, but `totalRaised` might be 0 from wrong currency selection
- If `primaryCurrency` logic fails, could show wrong average
- No validation that projects in calculation use same currency
---
### 4. **Empty useEffect Hook** 🐛
**Location:** Line 49-51
**Code:**
```typescript
useEffect(() => {
// REMOVED: console.log statement for security
}, [user, profile, session, isLoading, hydrated, authError, localLoading]);
```
**Problem:**
- Empty effect with dependencies - does nothing but runs on every change
- Unnecessary re-renders
- Should be removed entirely
**Fix:**
```typescript
// DELETE this entire useEffect
```
---
### 5. **Multiple Currency Logic Issues** ⚠️
**Location:** Lines 147-157
**Current Logic:**
```typescript
const primaryCurrency =
fundingByCurrency['CHF'] !== undefined
? 'CHF'
: fundingByCurrency['BTC'] !== undefined
? 'BTC'
: 'CHF';
```
**Problems:**
1. **Ignores other currencies** - If user has only EUR projects, shows CHF (wrong)
2. **Arbitrary priority** - Why CHF > BTC? Should be user preference or most common
3. **No indication of mixed currencies** - User might have CHF + EUR but only sees CHF total
4. **Total could be misleading** - Shows "2,500 CHF" but might have 1,000 EUR + 1,500 CHF
**Better Approach:**
- Show totals per currency when mixed
- Or convert all to single currency with clear indicator
- Or let user choose display currency
---
## 🟡 ENGINEERING ISSUES
### 6. **Large Component (743 lines)** ⚠️
**Problem:** Single file component is too large
**Issues:**
- Hard to maintain
- Hard to test
- Multiple responsibilities (data fetching, UI rendering, state management)
- Violates Single Responsibility Principle
**Recommendation:**
Extract into smaller components:
- `DashboardWelcome.tsx` - Welcome section
- `DashboardFeaturedProject.tsx` - Featured project card
- `DashboardStatsCards.tsx` - Stats grid
- `DashboardProjectsList.tsx` - Projects list
- `DashboardQuickActions.tsx` - Quick actions
---
### 7. **Business Logic in Component** ⚠️
**Location:** Throughout component
**Problems:**
- Currency calculation logic (lines 147-157) should be in utility
- Featured project selection logic (lines 174-179) should be in store or utility
- Profile completion calculation (lines 160-167) should be utility/hook
**Recommendation:**
```typescript
// src/utils/dashboard.ts
export function calculateTotalRaisedByCurrency(projects: Project[]): {
totals: Record<string, number>;
primaryCurrency: string;
};
export function selectFeaturedProject(projects: Project[]): Project | null;
// src/hooks/useProfileCompletion.ts
export function useProfileCompletion(profile: Profile | null): number;
```
---
### 8. **Missing Error Boundaries** ⚠️
**Problem:** No error boundaries to catch component errors
**Issues:**
- If project data is malformed, entire dashboard crashes
- No graceful degradation
- User sees blank page instead of helpful error
**Recommendation:**
- Wrap sections in Error Boundaries
- Add try-catch for data processing
- Show fallback UI for missing data
---
### 9. **Hardcoded Profile Category** ⚠️
**Location:** Line 182
```typescript
const profileCategory = PROFILE_CATEGORIES.individual;
```
**Problem:**
- Always shows "Individual" regardless of actual profile type
- Should read from `profile.category` or similar
- Could be misleading to users
---
### 10. **No Loading States for Async Operations** ⚠️
**Location:** Various
**Issues:**
- `projectLoading` is fetched but never used in render
- No loading indicator while projects load
- No skeleton UI for better UX
- Analytics loading state unused
**Recommendation:**
```typescript
{projectLoading ? (
<SkeletonLoader count={3} />
) : (
// Render projects
)}
```
---
### 11. **Inefficient Re-renders** ⚠️
**Location:** Multiple useEffects, computed values
**Issues:**
- `featuredProject` recalculated on every render (line 175)
- `fundingByCurrency` recalculated on every render (line 148)
- Should use `useMemo` for expensive calculations
**Recommendation:**
```typescript
const featuredProject = useMemo(() => {
// ... selection logic
}, [safeActiveProjects, safeProjects]);
const fundingByCurrency = useMemo(() => {
// ... calculation
}, [safeProjects]);
```
---
### 12. **Route Inconsistency - ACTUAL BUG** ⚠️
**Location:** Lines 285, 668
**Problem:**
- Dashboard uses `/project/${id}` (singular) - Line 285, 668
- But actual route structure:
- Public route: `/projects/[id]` (plural) ✅ unified route
- Old `/project/[id]`: Redirects to `/projects/[id]` ✅ backward compatibility
- **VERIFIED:** Both routes exist, but this is confusing!
**Issues:**
- Two different routes for same resource
- Users might get 404 if clicking from wrong context
- Codebase inconsistency (plural vs singular)
**Root Cause:**
- Public pages use `/projects/` (plural)
- Authenticated pages use `/project/` (singular)
- No route constants to standardize
**Recommendation:**
- Create route constants file
- Standardize to one pattern ✅ **COMPLETED** - All routes now use `/projects/[id]` (plural)
- Update all references
---
## 🟢 DESIGN & UX ISSUES
### 13. **Mixed Currency Display Confusion** ⚠️
**Location:** Lines 508, 574
**Problem:**
When projects have different currencies:
- "Total raised: 2,500.00 CHF" might exclude EUR/BTC projects
- User doesn't know if total is complete
- No indication that some projects excluded
**Recommendation:**
```typescript
// Show currency breakdown
{Object.keys(fundingByCurrency).length > 1 && (
<div className="text-xs text-gray-500">
Mixed currencies: {Object.keys(fundingByCurrency).join(', ')}
</div>
)}
```
---
### 14. **Empty State for "Recent Activity"** ⚠️
**Location:** Lines 720-739
**Problem:**
- Shows "Activity tracking coming soon" with no action
- Takes up space but provides no value
- Should either:
a) Hide when empty
b) Show actual activity
c) Remove entirely until feature ready
---
### 15. **Button Accessibility** ⚠️
**Location:** Multiple Button/Link components
**Issues:**
- Some buttons wrapped in Links (redundant)
- Missing aria-labels on icon-only buttons
- Keyboard navigation might be confusing
**Example:**
```typescript
<Link href={`/project/${project.id}`}>
<Button variant="outline" size="sm">
<Eye className="w-4 h-4" /> // No aria-label
</Button>
</Link>
```
**Fix:**
```typescript
<Button asChild variant="outline" size="sm" aria-label="View project">
<Link href={`/project/${project.id}`}>
<Eye className="w-4 h-4" />
</Link>
</Button>
```
---
### 16. **Inconsistent Spacing and Layout** ⚠️
**Location:** Throughout
**Issues:**
- Different padding values (`p-6`, `p-8`, `p-4`)
- Inconsistent gap sizes
- Some sections use `space-y-8`, others use `space-y-6`
- No consistent design system tokens
**Recommendation:**
- Use consistent spacing scale
- Create spacing constants
- Use Tailwind's spacing scale consistently
---
### 17. **Featured Project Selection Logic** ⚠️
**Location:** Lines 174-179
```typescript
const featuredProject =
safeActiveProjects.length > 0
? safeActiveProjects.sort((a, b) => (b.total_funding || 0) - (a.total_funding || 0))[0]
: safeProjects.find(c => c.title?.toLowerCase().includes('orange cat')) || safeProjects[0];
```
**Problems:**
1. **Sorts array in place** - mutates original array (bad practice)
2. **Hardcoded "orange cat"** - magic string, not user-centric
3. **Falls back to first project** - might be draft/inactive
4. **No user preference** - user can't choose featured project
**Recommendation:**
```typescript
const featuredProject = useMemo(() => {
// Sort copy, not original
const sorted = [...safeActiveProjects].sort(...);
// Or use user preference
// Or most recent active
return sorted[0] || null;
}, [safeActiveProjects]);
```
---
## 🎨 DESIGN IMPROVEMENTS
### 18. **Visual Hierarchy** ✅ Mostly Good
- Welcome section is prominent
- Featured project stands out
- Card grid is organized
**Minor Improvements:**
- Could add subtle animations on load
- Progress bars could be more prominent
- Empty states could be more engaging
---
### 19. **Color Consistency** ✅ Good
- Bitcoin orange used appropriately
- Status badges are clear
- Error states use red appropriately
---
### 20. **Responsive Design** ✅ Good
- Uses responsive grid classes
- Mobile-first approach visible
- Breakpoints are appropriate
**Minor Issue:**
- Some text could wrap better on mobile
- Button groups might overflow on small screens
---
## 📊 BEST PRACTICES ANALYSIS
### ✅ GOOD PRACTICES
- [x] Error handling for auth state
- [x] Loading states present
- [x] Safe array checks before reduce
- [x] TypeScript types used
- [x] Modular component structure (uses Card, Button, etc.)
- [x] Accessible HTML structure
- [x] Responsive design
### ❌ NEEDS IMPROVEMENT
- [ ] Type system matches actual data
- [ ] Business logic extracted to utilities
- [ ] Large component split into smaller ones
- [ ] Memoization for expensive calculations
- [ ] Error boundaries added
- [ ] Loading states for async data
- [ ] Consistent route naming
- [ ] Accessibility labels on icons
- [ ] No empty useEffect hooks
---
## 🔧 SPECIFIC FIXES NEEDED
### Priority 0 (Critical - Fix Immediately)
1. **Fix Currency Type Definition**
```typescript
// src/types/funding.ts
currency?: 'BTC' | 'SATS' | 'CHF' | 'USD' | 'EUR' | string;
```
2. **Explicit Currency in Project Store**
```typescript
// src/stores/projectStore.ts
currency: project.currency || 'CHF',
```
3. **Remove Empty useEffect**
```typescript
// DELETE lines 48-51
```
4. **Fix Featured Project Selection**
```typescript
const featuredProject = useMemo(() => {
if (safeActiveProjects.length === 0) return null;
const sorted = [...safeActiveProjects].sort(
(a, b) => (b.total_funding || 0) - (a.total_funding || 0)
);
return sorted[0];
}, [safeActiveProjects]);
```
### Priority 1 (High - Fix Soon)
5. **Extract Business Logic**
- Create `src/utils/dashboard.ts` for calculations
- Create `src/hooks/useProfileCompletion.ts`
6. **Add Memoization**
- Wrap expensive calculations in `useMemo`
- Optimize re-renders
7. **Add Loading States**
- Show skeleton while projects load
- Use `projectLoading` state
8. **Fix Route Consistency**
- Verify all routes use same pattern
- Use route constants
### Priority 2 (Medium - Nice to Have)
9. **Component Extraction**
- Split into smaller components
- Better separation of concerns
10. **Error Boundaries**
- Add React Error Boundaries
- Graceful error handling
11. **Accessibility Improvements**
- Add aria-labels
- Improve keyboard navigation
- Test with screen readers
12. **Mixed Currency Display**
- Show currency breakdown
- Or allow user to choose display currency
---
## 📈 PERFORMANCE CONSIDERATIONS
### Current Issues:
1. **No memoization** - Recalculates on every render
2. **Array mutations** - `.sort()` mutates original
3. **Multiple useEffects** - Could be consolidated
4. **Large component** - Re-renders entire tree on state change
### Recommendations:
- Use `useMemo` for derived state
- Use `useCallback` for event handlers
- Lazy load heavy sections
- Virtualize long lists if needed
---
## 🧪 TESTING SCENARIOS
### Critical Test Cases:
1. **Type Safety**
- Project with CHF currency doesn't cause TypeScript errors
- Currency display works for all supported currencies
2. **Empty States**
- No projects shows appropriate empty state
- No drafts shows no draft section
- No profile shows profile completion prompt
3. **Mixed Currencies**
- Projects with CHF + BTC show correctly
- Total calculation doesn't mix currencies incorrectly
4. **Error Handling**
- Failed project load shows error state
- Malformed project data doesn't crash dashboard
5. **Loading States**
- Projects loading shows loading indicator
- Analytics loading doesn't block UI
---
## 🎯 RECOMMENDED REFACTORING PLAN
### Phase 1: Critical Fixes (Do First)
1. ✅ Fix currency type definition
2. ✅ Fix project store currency mapping
3. ✅ Remove empty useEffect
4. ✅ Fix featured project selection
5. ✅ Add memoization for calculations
### Phase 2: Code Quality (Do Next)
6. ✅ Extract business logic to utilities
7. ✅ Add loading states
8. ✅ Fix route consistency
9. ✅ Add error boundaries
### Phase 3: Architecture (Do Later)
10. ✅ Split large component
11. ✅ Create custom hooks
12. ✅ Add comprehensive tests
---
## 📝 SUMMARY
### Issues Found:
- **4 Critical Errors** (Type mismatch, missing fields, empty hooks, logic bugs)
- **8 Engineering Issues** (Large component, logic in component, no memoization, etc.)
- **7 Design/UX Issues** (Mixed currencies, empty states, accessibility, etc.)
- **3 Performance Issues** (No memoization, array mutations, re-renders)
### Total: 22 Issues Identified
### Priority Breakdown:
- **P0 (Critical):** 4 issues - Fix immediately
- **P1 (High):** 8 issues - Fix soon
- **P2 (Medium):** 10 issues - Fix when time allows
---
## ✅ STRENGTHS TO MAINTAIN
1. **Good Error Handling** - Auth errors handled well
2. **Safe Array Operations** - Prevents runtime errors
3. **Responsive Design** - Works on mobile
4. **Visual Design** - Modern, clean, professional
5. **Loading States** - Basic loading handled
6. **TypeScript Usage** - Types used throughout
---
## 🚀 NEXT STEPS
**Immediate Actions:**
1. Fix currency type definition (5 minutes)
2. Add explicit currency to project store (2 minutes)
3. Remove empty useEffect (1 minute)
4. Fix featured project selection with useMemo (5 minutes)
**Short-term (This Week):** 5. Extract business logic (2-3 hours) 6. Add loading states (1-2 hours) 7. Add memoization (1 hour)
**Long-term (This Sprint):** 8. Component extraction (4-6 hours) 9. Error boundaries (2-3 hours) 10. Comprehensive testing (4-6 hours)
---
## 📚 REFERENCES
- React Best Practices: https://react.dev/learn
- TypeScript Best Practices: Type-safe code
- Accessibility Guidelines: WCAG 2.1
- Performance: React Performance Optimization