// components/workout/WorkoutOfflineState.tsx import React from 'react'; import { View, TouchableOpacity } from 'react-native'; import { Text } from '@/components/ui/text'; import { WifiOffIcon, RefreshCwIcon, ArrowLeftIcon } from 'lucide-react-native'; import { useConnectivity } from '@/lib/db/services/ConnectivityService'; import { useRouter } from 'expo-router'; interface WorkoutOfflineStateProps { workoutId?: string; } export default function WorkoutOfflineState({ workoutId }: WorkoutOfflineStateProps) { const { lastOnlineTime, checkConnection } = useConnectivity(); const router = useRouter(); // Format last online time const lastOnlineText = lastOnlineTime ? `Last online: ${new Date(lastOnlineTime).toLocaleDateString()} at ${new Date(lastOnlineTime).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}` : 'Not connected recently'; // Handle manual refresh attempt const handleRefresh = () => { checkConnection(); }; // Handle go back const handleGoBack = () => { router.back(); }; return ( You're offline {workoutId ? "This workout can't be loaded while you're offline. Please check your connection and try again." : "Workout details can't be loaded while you're offline. Please check your connection and try again."} {lastOnlineText} Go Back Check Connection ); } /** * A higher-order component that wraps workout detail screens to handle offline state */ export function withWorkoutOfflineState

( Component: React.ComponentType

): React.FC

{ return (props: P & { workoutId?: string; workout?: any }) => { const { isOnline } = useConnectivity(); // If we're online or we already have the workout data locally, show the component if (isOnline || props.workout) { return ; } // Otherwise show the offline state return ; }; }