// app/(workout)/template/[id]/history.tsx import React, { useState, useEffect } from 'react'; import { View, ScrollView, ActivityIndicator } from 'react-native'; import { Text } from '@/components/ui/text'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Card, CardContent } from '@/components/ui/card'; import { Calendar } from 'lucide-react-native'; import { useTemplate } from './_templateContext'; // Format date helper const formatDate = (date: Date) => { return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' }); }; // Mock workout history - this would come from your database in a real app const mockWorkoutHistory = [ { id: 'hist1', date: new Date(2024, 1, 25), duration: 62, // minutes completed: true, notes: "Increased weight on squats by 10lbs", exercises: [ { name: "Barbell Squat", sets: 3, reps: 8, weight: 215 }, { name: "Bench Press", sets: 3, reps: 8, weight: 175 }, { name: "Bent Over Row", sets: 3, reps: 8, weight: 155 } ] }, { id: 'hist2', date: new Date(2024, 1, 18), duration: 58, // minutes completed: true, exercises: [ { name: "Barbell Squat", sets: 3, reps: 8, weight: 205 }, { name: "Bench Press", sets: 3, reps: 8, weight: 175 }, { name: "Bent Over Row", sets: 3, reps: 8, weight: 155 } ] }, { id: 'hist3', date: new Date(2024, 1, 11), duration: 65, // minutes completed: false, notes: "Stopped early due to time constraints", exercises: [ { name: "Barbell Squat", sets: 3, reps: 8, weight: 205 }, { name: "Bench Press", sets: 3, reps: 8, weight: 170 }, { name: "Bent Over Row", sets: 2, reps: 8, weight: 150 } ] } ]; export default function HistoryTab() { const template = useTemplate(); const [isLoading, setIsLoading] = useState(false); // Simulate loading history data useEffect(() => { const loadHistory = async () => { setIsLoading(true); // Simulate loading delay await new Promise(resolve => setTimeout(resolve, 500)); setIsLoading(false); }; loadHistory(); }, [template.id]); return ( {/* Performance Summary */} Performance Summary Total Workouts {mockWorkoutHistory.length} Avg Duration {Math.round(mockWorkoutHistory.reduce((acc, w) => acc + w.duration, 0) / mockWorkoutHistory.length)} min Completion {Math.round(mockWorkoutHistory.filter(w => w.completed).length / mockWorkoutHistory.length * 100)}% {/* History List */} Workout History {isLoading ? ( Loading history... ) : mockWorkoutHistory.length > 0 ? ( {mockWorkoutHistory.map((workout) => ( {formatDate(workout.date)} {workout.completed ? "Completed" : "Incomplete"} Duration {workout.duration} min Sets {workout.exercises.reduce((acc, ex) => acc + ex.sets, 0)} Volume {workout.exercises.reduce((acc, ex) => acc + (ex.sets * ex.reps * ex.weight), 0)} lbs {workout.notes && ( {workout.notes} )} ))} ) : ( No workout history available yet Complete a workout using this template to see your history )} ); }