// app/(tabs)/profile/activity.tsx import React, { useState, useEffect } from 'react'; import { View, ScrollView, Pressable } from 'react-native'; import { Text } from '@/components/ui/text'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { useNDKCurrentUser } from '@/lib/hooks/useNDK'; import { ActivityIndicator } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import NostrLoginSheet from '@/components/sheets/NostrLoginSheet'; import { useRouter } from 'expo-router'; import { useAnalytics } from '@/lib/hooks/useAnalytics'; import { PersonalRecord } from '@/lib/services/AnalyticsService'; import { formatDistanceToNow } from 'date-fns'; import { useWorkouts } from '@/lib/hooks/useWorkouts'; import { useTemplates } from '@/lib/hooks/useTemplates'; import WorkoutCard from '@/components/workout/WorkoutCard'; import { Dumbbell, BarChart2, Award, Calendar } from 'lucide-react-native'; export default function ActivityScreen() { const insets = useSafeAreaInsets(); const router = useRouter(); const { isAuthenticated } = useNDKCurrentUser(); const analytics = useAnalytics(); const { workouts, loading: workoutsLoading } = useWorkouts(); const { templates, loading: templatesLoading } = useTemplates(); const [isLoginSheetOpen, setIsLoginSheetOpen] = useState(false); const [records, setRecords] = useState([]); const [loading, setLoading] = useState(true); // Stats const completedWorkouts = workouts?.filter(w => w.isCompleted)?.length || 0; const totalTemplates = templates?.length || 0; const totalPrograms = 0; // Placeholder for programs count // 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]); // Show different UI when not authenticated if (!isAuthenticated) { return ( Login with your Nostr private key to view your activity and stats. {/* NostrLoginSheet */} setIsLoginSheetOpen(false)} /> ); } if (loading || workoutsLoading || templatesLoading) { return ( ); } return ( {/* Stats Cards - Row 1 */} {completedWorkouts} Workouts {totalTemplates} Templates {/* Stats Cards - Row 2 */} {totalPrograms} Programs {records.length} PRs {/* 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 */} 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. )} {/* Quick Actions */} ); }