"use client" import { useState, useEffect } from 'react' import { motion } from 'framer-motion' import { Wifi, WifiOff, CheckCircle, XCircle, RefreshCw, ArrowLeft } from 'lucide-react' import Link from 'next/link' export default function OfflineTestPage() { const [isOnline, setIsOnline] = useState(true) const [serviceWorkerStatus, setServiceWorkerStatus] = useState('checking') const [cacheStatus, setCacheStatus] = useState('checking') useEffect(() => { // Check online status const updateOnlineStatus = () => { setIsOnline(navigator.onLine) } window.addEventListener('online', updateOnlineStatus) window.addEventListener('offline', updateOnlineStatus) updateOnlineStatus() // Check service worker status if ('serviceWorker' in navigator) { navigator.serviceWorker.ready.then((registration) => { if (registration.active) { setServiceWorkerStatus('active') } else { setServiceWorkerStatus('inactive') } }).catch(() => { setServiceWorkerStatus('error') }) } else { setServiceWorkerStatus('not-supported') } // Check cache status if ('caches' in window) { caches.open('passmaster-v1.0.0').then((cache) => { cache.keys().then((keys) => { if (keys.length > 0) { setCacheStatus('cached') } else { setCacheStatus('empty') } }) }).catch(() => { setCacheStatus('error') }) } else { setCacheStatus('not-supported') } return () => { window.removeEventListener('online', updateOnlineStatus) window.removeEventListener('offline', updateOnlineStatus) } }, []) const getStatusIcon = (status: string) => { switch (status) { case 'active': case 'cached': return case 'inactive': case 'empty': case 'error': return case 'checking': return default: return } } const getStatusText = (status: string) => { switch (status) { case 'active': return 'Service Worker Active' case 'inactive': return 'Service Worker Inactive' case 'error': return 'Service Worker Error' case 'not-supported': return 'Service Worker Not Supported' case 'cached': return 'Resources Cached' case 'empty': return 'Cache Empty' case 'checking': return 'Checking...' default: return 'Unknown Status' } } return (
{/* Header */}
Back to PassMaster
{/* Hero Section */}
{isOnline ? ( ) : ( )}

Offline Functionality Test

Test your PWA's offline capabilities and service worker status.

{/* Status Cards */}
{/* Connection Status */}

Connection Status

{isOnline ? ( ) : ( )}

{isOnline ? 'You are currently online' : 'You are currently offline'}

{/* Service Worker Status */}

Service Worker

{getStatusIcon(serviceWorkerStatus)}

{getStatusText(serviceWorkerStatus)}

{/* Cache Status */}

Cache Status

{getStatusIcon(cacheStatus)}

{getStatusText(cacheStatus)}

{/* PWA Status */}

PWA Status

{isOnline && serviceWorkerStatus === 'active' && cacheStatus === 'cached' ? 'Ready for offline use' : 'Some features may not work offline'}

{/* Instructions */}

How to Test Offline Functionality

1

Make sure you're online and the service worker is active (green checkmark above)

2

Navigate to the main page and let it fully load

3

Disconnect your internet connection (turn off WiFi or unplug ethernet)

4

Try navigating back to the main page - it should still work offline!

{/* Action Buttons */} Go to Main Page
) }