import { useState, useEffect, lazy, Suspense } from 'react'; import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; import { QueryClient, QueryClientProvider } from 'react-query'; import { Sidebar } from './components/layout/Sidebar'; import { Header } from './components/layout/Header'; import { Footer } from './components/layout/Footer'; import { LandingPage } from './pages/LandingPage'; import { NewOrderPage } from './pages/NewOrderPage'; import { LoginPage } from './pages/LoginPage'; import { PaymentSuccessPage } from './pages/PaymentSuccessPage'; import { Chatbot } from './components/support/Chatbot'; import { OrderProvider } from './contexts/OrderContext'; import { AuthProvider } from './contexts/AuthContext'; import { AdminAuthProvider } from './contexts/AdminAuthContext'; import RequireAuth from './components/auth/RequireAuth'; import RequireRole from './components/auth/RequireRole'; import { AdminRoute } from './components/auth/AdminRoute'; import { PaymentProvider } from './contexts/PaymentContext'; import { ReviewProvider } from './contexts/ReviewContext'; import { LoyaltyProvider } from './contexts/LoyaltyContext'; import { ScrollToTop } from './components/utils/ScrollToTop'; import { usePWA } from './hooks/usePWA'; import { useNotifications } from './hooks/useNotifications'; import { preloadCriticalAssets } from './lib/preload'; // Lazy load less critical pages for better initial load performance const AllOrdersPage = lazy(() => import('./pages/AllOrdersPage').then(m => ({ default: m.AllOrdersPage }))); const AnalyticsDashboard = lazy(() => import('./pages/AnalyticsDashboard').then(m => ({ default: m.AnalyticsDashboard }))); const ScheduledOrdersPage = lazy(() => import('./pages/ScheduledOrdersPage').then(m => ({ default: m.ScheduledOrdersPage }))); const OrderDetailPage = lazy(() => import('./pages/OrderDetailPage').then(m => ({ default: m.OrderDetailPage }))); const TestimonialsPage = lazy(() => import('./pages/TestimonialsPage').then(m => ({ default: m.TestimonialsPage }))); const AdminLogin = lazy(() => import('./pages/admin/AdminLogin').then(m => ({ default: m.AdminLogin }))); const AdminDashboard = lazy(() => import('./pages/admin/AdminDashboard').then(m => ({ default: m.AdminDashboard }))); const AdminTestimonials = lazy(() => import('./pages/admin/AdminTestimonials').then(m => ({ default: m.AdminTestimonials }))); const AdminAllOrders = lazy(() => import('./pages/admin/AdminAllOrders').then(m => ({ default: m.AdminAllOrders }))); const queryClient = new QueryClient(); // Loading spinner component for lazy-loaded routes function LoadingFallback() { return (
Loading...