# Activity Tab **Last Updated:** 2025-04-02 **Status:** Implemented **Related To:** [Profile Tab Overview](../profile_overview.md), [Progress Tab](./progress_tab.md) ## Introduction The Activity tab provides users with a summary of their workout activities, including statistics, recent workouts, and personal records. It serves as a quick overview dashboard for tracking workout progress and achievements. ## Features | Feature | Status | Notes | |---------|--------|-------| | Workout Stats Cards | ✅ Implemented | Shows completed workouts, templates, programs, and PRs | | Personal Records | ✅ Implemented | Lists recent personal records with dates | | Recent Workouts | ✅ Implemented | Shows most recent completed workouts | | Quick Action Buttons | ✅ Implemented | Navigation to start workout and view progress | | Authentication Detection | ✅ Implemented | Login prompt for unauthenticated users | | Integration with Analytics | ✅ Implemented | Uses AnalyticsService for workout statistics | ## Implementation Details The Activity tab is implemented in `app/(tabs)/profile/activity.tsx`. It integrates with the AnalyticsService for personal records and the WorkoutService for workout history. ### Stats Cards Implementation The Activity tab displays four key statistics in card format: ```jsx {/* Stats Cards - Row 1 */} {completedWorkouts} Workouts {totalTemplates} Templates {/* Stats Cards - Row 2 */} {totalPrograms} Programs {records.length} PRs ``` ### Personal Records Implementation The Activity tab displays the user's personal records: ```jsx {/* Personal Records */} Personal Records router.push('/profile/progress')}> View All {records.length === 0 ? ( No personal records yet. Complete more workouts to see your progress. ) : ( records.map((record) => ( {record.exerciseName} {record.value} {record.unit} × {record.reps} reps {formatDistanceToNow(new Date(record.date), { addSuffix: true })} )) )} ``` ### Recent Workouts Implementation The tab also shows the user's most recent completed workouts: ```jsx {/* Recent Workouts */} Recent Workouts router.push('/history/workoutHistory')}> View All {workouts && workouts.length > 0 ? ( workouts .filter(workout => workout.isCompleted) .slice(0, 2) .map(workout => ( )) ) : ( No recent workouts. Complete a workout to see it here. )} ``` ### Analytics Integration The Activity tab integrates with the AnalyticsService to display personal records: ```jsx // Load personal records useEffect(() => { async function loadRecords() { if (!isAuthenticated) return; try { setLoading(true); const personalRecords = await analytics.getPersonalRecords(undefined, 3); setRecords(personalRecords); } catch (error) { console.error('Error loading personal records:', error); } finally { setLoading(false); } } loadRecords(); }, [isAuthenticated, analytics]); ``` ## Technical Considerations ### Authentication Handling Like other profile tabs, the Activity tab handles authentication with a consistent pattern: ```jsx // Show different UI when not authenticated if (!isAuthenticated) { return ; } ``` ### Data Loading The component manages loading states and provides appropriate UI feedback: ```jsx if (loading || workoutsLoading || templatesLoading) { return ( ); } ``` ### Hook Dependencies The component carefully manages effect hook dependencies to prevent unnecessary re-renders: ```jsx useEffect(() => { async function loadRecords() { // ...implementation } loadRecords(); }, [isAuthenticated, analytics]); // Only rerun when these dependencies change ``` ## User Experience Flow 1. **Authentication Check**: - If user is not authenticated, display NostrProfileLogin component - If authenticated, proceed to load activity data 2. **Data Loading**: - Fetch completed workouts count from WorkoutService - Load templates count from TemplateService - Fetch personal records from AnalyticsService - Show loading indicator during data fetch 3. **Data Display**: - Show stats cards with summary numbers - Display recent personal records with details - Show recent completed workouts with WorkoutCard component - Provide quick action buttons for common tasks 4. **Navigation Options**: - "View All" links to relevant detailed screens (Progress, History) - Quick action buttons for starting a workout or viewing progress ## Future Enhancements 1. **Programs Integration**: Complete implementation of programs count when feature is available 2. **Additional Stats**: Add more workout statistics like total volume, duration 3. **Enhanced Personal Records**: Add visual indicators for progress trends 4. **Streak Tracking**: Add workout streak and consistency metrics 5. **Workout Insights**: Add AI-generated insights based on workout patterns ## Related Documentation - [Profile Overview](../profile_overview.md) - General overview of the Profile tab - [Progress Tab](./progress_tab.md) - Documentation for the detailed progress tracking tab - [Analytics Service](../../../technical/analytics/index.md) - Details on workout analytics implementation - [WorkoutCard Component](../../../components/workout_card.md) - Documentation for the WorkoutCard component used in this tab