import { useState, useEffect } from 'react' import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom' import { AuthProvider, useAuth } from './context/AuthContext' import { DeveloperModeProvider } from './context/DeveloperModeContext' import Login from './pages/Login' import Dashboard from './pages/Dashboard' import Search from './pages/Search' import Scan from './pages/Scan' import Process from './pages/Process' import Identify from './pages/Identify' import AutoMatch from './pages/AutoMatch' import Modify from './pages/Modify' import Tags from './pages/Tags' import FacesMaintenance from './pages/FacesMaintenance' import ApproveIdentified from './pages/ApproveIdentified' import ManageUsers from './pages/ManageUsers' import ReportedPhotos from './pages/ReportedPhotos' import PendingPhotos from './pages/PendingPhotos' import UserTaggedPhotos from './pages/UserTaggedPhotos' import ManagePhotos from './pages/ManagePhotos' import Settings from './pages/Settings' import Help from './pages/Help' import Layout from './components/Layout' import PasswordChangeModal from './components/PasswordChangeModal' import AdminRoute from './components/AdminRoute' import { logClick, flushPendingClicks } from './services/clickLogger' function PrivateRoute({ children }: { children: React.ReactNode }) { const { isAuthenticated, isLoading, passwordChangeRequired } = useAuth() const [showPasswordModal, setShowPasswordModal] = useState(false) useEffect(() => { if (isAuthenticated && passwordChangeRequired) { setShowPasswordModal(true) } }, [isAuthenticated, passwordChangeRequired]) if (isLoading) { return
Loading...
} if (!isAuthenticated) { return } return ( <> {showPasswordModal && ( { setShowPasswordModal(false) }} /> )} {children} ) } function AppRoutes() { const { isAuthenticated } = useAuth() // Set up global click logging for authenticated users useEffect(() => { if (!isAuthenticated) { return } const handleClick = (event: MouseEvent) => { const target = event.target as HTMLElement if (target) { logClick(target) } } // Add click listener document.addEventListener('click', handleClick, true) // Use capture phase // Flush pending clicks on page unload const handleBeforeUnload = () => { flushPendingClicks() } window.addEventListener('beforeunload', handleBeforeUnload) return () => { document.removeEventListener('click', handleClick, true) window.removeEventListener('beforeunload', handleBeforeUnload) // Flush any pending clicks on cleanup flushPendingClicks() } }, [isAuthenticated]) return ( } /> } > } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> ) } function App() { return ( ) } export default App