import React, { useState, useRef } from 'react'; import { View, Text, StyleSheet, ActivityIndicator, TouchableOpacity } from 'react-native'; import { WebView } from 'react-native-webview'; import { Ionicons } from '@expo/vector-icons'; import { SafeAreaView } from 'react-native-safe-area-context'; import * as SecureStore from 'expo-secure-store'; import { AppColors, FontSizes, Spacing } from '@/constants/theme'; import { FullScreenError } from '@/components/ui/ErrorMessage'; const DASHBOARD_URL = 'https://react.eluxnetworks.net/dashboard'; export default function DashboardScreen() { const webViewRef = useRef(null); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const [canGoBack, setCanGoBack] = useState(false); const handleRefresh = () => { setError(null); setIsLoading(true); webViewRef.current?.reload(); }; const handleBack = () => { if (canGoBack) { webViewRef.current?.goBack(); } }; const handleNavigationStateChange = (navState: any) => { setCanGoBack(navState.canGoBack); }; const handleError = () => { setError('Failed to load dashboard. Please check your internet connection.'); setIsLoading(false); }; if (error) { return ( ); } return ( {/* Header */} {canGoBack && ( )} {/* Empty title - WebView has its own dashboard header */} {/* WebView */} setIsLoading(true)} onLoadEnd={() => setIsLoading(false)} onError={handleError} onHttpError={handleError} onNavigationStateChange={handleNavigationStateChange} javaScriptEnabled={true} domStorageEnabled={true} startInLoadingState={true} scalesPageToFit={true} allowsBackForwardNavigationGestures={true} renderLoading={() => ( Loading dashboard... )} /> {isLoading && ( )} ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: AppColors.background, }, header: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: Spacing.md, paddingVertical: Spacing.sm, backgroundColor: AppColors.background, borderBottomWidth: 1, borderBottomColor: AppColors.border, }, backButton: { padding: Spacing.xs, marginRight: Spacing.sm, }, headerTitle: { flex: 1, fontSize: FontSizes.xl, fontWeight: '700', color: AppColors.textPrimary, }, headerTitleWithBack: { marginLeft: 0, }, refreshButton: { padding: Spacing.xs, }, webViewContainer: { flex: 1, }, webView: { flex: 1, }, loadingContainer: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center', backgroundColor: AppColors.background, }, loadingOverlay: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center', backgroundColor: 'rgba(255,255,255,0.8)', }, loadingText: { marginTop: Spacing.md, fontSize: FontSizes.base, color: AppColors.textSecondary, }, });