import "tldraw/tldraw.css"; import "@/css/style.css"; import "@/css/auth.css"; // Import auth styles import "@/css/crypto-auth.css"; // Import crypto auth styles import "@/css/starred-boards.css"; // Import starred boards styles import "@/css/user-profile.css"; // Import user profile styles import { BrowserRouter, Route, Routes, Navigate, useParams } from "react-router-dom"; import { createRoot } from "react-dom/client"; import { useState, useEffect, lazy, Suspense } from 'react'; // Lazy load heavy route components for faster initial load const Default = lazy(() => import("@/routes/Default").then(m => ({ default: m.Default }))); const Contact = lazy(() => import("@/routes/Contact").then(m => ({ default: m.Contact }))); const Board = lazy(() => import("./routes/Board").then(m => ({ default: m.Board }))); const Inbox = lazy(() => import("./routes/Inbox").then(m => ({ default: m.Inbox }))); const Presentations = lazy(() => import("./routes/Presentations").then(m => ({ default: m.Presentations }))); const Resilience = lazy(() => import("./routes/Resilience").then(m => ({ default: m.Resilience }))); const Dashboard = lazy(() => import("./routes/Dashboard").then(m => ({ default: m.Dashboard }))); // Import React Context providers import { AuthProvider, useAuth } from './context/AuthContext'; import { FileSystemProvider } from './context/FileSystemContext'; import { NotificationProvider } from './context/NotificationContext'; import NotificationsDisplay from './components/NotificationsDisplay'; import { ErrorBoundary } from './components/ErrorBoundary'; // Import auth components import CryptID from './components/auth/CryptID'; import CryptoDebug from './components/auth/CryptoDebug'; // Import Google Data test component import { GoogleDataTest } from './components/GoogleDataTest'; // Lazy load Daily.co provider - only needed for video chat const DailyProvider = lazy(() => import('@daily-co/daily-react').then(m => ({ default: m.DailyProvider })) ); // Loading skeleton for lazy-loaded routes const LoadingSpinner = () => (

Loading canvas...

); // Daily.co call object - initialized lazily when needed let dailyCallObject: any = null; const getDailyCallObject = async () => { if (dailyCallObject) return dailyCallObject; try { // Only create call object if we're in a secure context and mediaDevices is available if (typeof window !== 'undefined' && window.location.protocol === 'https:' && navigator.mediaDevices) { const Daily = (await import('@daily-co/daily-js')).default; dailyCallObject = Daily.createCallObject(); } } catch (error) { console.warn('Daily.co call object initialization failed:', error); } return dailyCallObject; }; /** * Optional Auth Route component * Allows guests to browse, but provides login option */ const OptionalAuthRoute = ({ children }: { children: React.ReactNode }) => { const { session } = useAuth(); const [isInitialized, setIsInitialized] = useState(false); // Wait for authentication to initialize before rendering useEffect(() => { if (!session.loading) { setIsInitialized(true); } }, [session.loading]); if (!isInitialized) { return
Loading...
; } // Always render the content, authentication is optional return <>{children}; }; /** * Component to redirect board URLs without trailing slashes */ const RedirectBoardSlug = () => { const { slug } = useParams<{ slug: string }>(); return ; }; /** * Main App with context providers */ const AppWithProviders = () => { /** * Auth page - renders login/register component (kept for direct access) */ const AuthPage = () => { const { session } = useAuth(); // Redirect to home if already authenticated if (session.authed) { return ; } return (
window.location.href = '/'} />
); }; return ( }> {/* Display notifications */} }> {/* Redirect routes without trailing slashes to include them */} } /> } /> } /> } /> } /> } /> } /> } /> {/* Auth routes */} } /> {/* Optional auth routes - all lazy loaded */} } /> } /> } /> } /> } /> } /> } /> } /> {/* Google Data routes */} } /> } /> ); }; // Initialize the app createRoot(document.getElementById("root")!).render(); export default AppWithProviders;