import * as React from 'react'; import Head from 'next/head'; import Link from 'next/link'; import { MobileHeader, BottomNav } from 'components/mobile'; import { isOnline, getPendingPlants, getPendingTransport, clearCachedPlants } from 'lib/mobile/offline'; import { getPWAStatus, promptInstall, clearCaches } from 'lib/mobile/pwa'; interface ProfileStats { plantsRegistered: number; co2Saved: number; foodMiles: number; generation: number; } export default function ProfilePage() { const [online, setOnline] = React.useState(true); const [pwaStatus, setPwaStatus] = React.useState(() => getPWAStatus()); const [pendingSync, setPendingSync] = React.useState({ plants: 0, transport: 0 }); const [stats] = React.useState({ plantsRegistered: 24, co2Saved: 12.5, foodMiles: 156, generation: 3, }); React.useEffect(() => { setOnline(isOnline()); const handleOnline = () => { setOnline(true); setPwaStatus(getPWAStatus()); }; const handleOffline = () => setOnline(false); window.addEventListener('online', handleOnline); window.addEventListener('offline', handleOffline); // Load pending items count const loadPending = async () => { const plants = await getPendingPlants(); const transport = await getPendingTransport(); setPendingSync({ plants: plants.length, transport: transport.length }); }; loadPending(); return () => { window.removeEventListener('online', handleOnline); window.removeEventListener('offline', handleOffline); }; }, []); const handleInstall = async () => { const success = await promptInstall(); if (success) { setPwaStatus(getPWAStatus()); } }; const handleClearCache = async () => { if (confirm('Are you sure you want to clear all cached data?')) { await clearCaches(); await clearCachedPlants(); alert('Cache cleared successfully'); } }; return ( <> Profile - LocalGreenChain
{/* Profile header */}

Local Grower

Member since 2024

{online ? 'Online' : 'Offline'}
{/* Stats */}

Your Stats

{stats.plantsRegistered}

Plants Registered

{stats.co2Saved} kg

CO2 Saved

{stats.foodMiles}

Food Miles Tracked

Gen {stats.generation}

Max Generation

{/* Pending sync */} {(pendingSync.plants > 0 || pendingSync.transport > 0) && (

Pending Sync

{pendingSync.plants} plants and {pendingSync.transport} transport events will sync when you're online.

)} {/* App settings */}

App Settings

{/* Install PWA */} {!pwaStatus.isInstalled && pwaStatus.canInstall && ( )} {/* Notifications */}

Notifications

Manage push notifications

{/* Privacy */}

Privacy

Location, data sharing

{/* Clear cache */}
{/* About */}

About

Version 1.0.0
App Mode {pwaStatus.isStandalone ? 'Standalone' : 'Browser'}
Switch to Desktop
); }