import React, { useState, useEffect, Suspense } from 'react'; import { GameProvider } from './context/GameContext'; import { Monitor, Smartphone, LayoutDashboard, Loader2 } from 'lucide-react'; // Lazy load components to reduce initial bundle size const HostView = React.lazy(() => import('./components/HostView').then(module => ({ default: module.HostView }))); const PlayerView = React.lazy(() => import('./components/PlayerView').then(module => ({ default: module.PlayerView }))); const SpectatorView = React.lazy(() => import('./components/SpectatorView').then(module => ({ default: module.SpectatorView }))); const App: React.FC = () => { const [view, setView] = useState<'HOST' | 'PLAYER' | 'SPECTATOR'>('SPECTATOR'); // Simple hash routing for demo purposes useEffect(() => { const handleHashChange = () => { const hash = window.location.hash; if (hash === '#host') setView('HOST'); else if (hash === '#player') setView('PLAYER'); else setView('SPECTATOR'); }; handleHashChange(); window.addEventListener('hashchange', handleHashChange); return () => window.removeEventListener('hashchange', handleHashChange); }, []); const navigate = (newView: 'HOST' | 'PLAYER' | 'SPECTATOR') => { setView(newView); window.location.hash = newView.toLowerCase(); }; const renderView = () => { switch (view) { case 'HOST': return ; case 'PLAYER': return ; case 'SPECTATOR': return ; default: return ; } }; return ( {/* Top Navigation Bar */} Q QuizMaster Live navigate('SPECTATOR')} icon={} label="Spectator" /> navigate('HOST')} icon={} label="Host" /> navigate('PLAYER')} icon={} label="Player" /> {/* Main Content Area */} Loading Quiz Module... }> {renderView()} ); }; interface NavButtonProps { active: boolean; onClick: () => void; icon: React.ReactNode; label: string; } const NavButton: React.FC = ({ active, onClick, icon, label }) => ( {icon} {label} ); export default App;
Loading Quiz Module...