diff --git a/apps/roadrunner-view/src/App.tsx b/apps/roadrunner-view/src/App.tsx index d658090..74d93a1 100644 --- a/apps/roadrunner-view/src/App.tsx +++ b/apps/roadrunner-view/src/App.tsx @@ -27,6 +27,28 @@ const HomeRedirect = () => { return ; }; +const ProviderEnforcedRoute = ({ requiredProvider, component: Component }: { requiredProvider: 'google' | 'mapbox'; component: React.ComponentType }) => { + const provider = (localStorage.getItem('roadrunner_map_provider') as 'google' | 'mapbox') || 'google'; + if (provider !== requiredProvider) { + const search = window.location.search; + const path = window.location.pathname; + let newPath = ''; + if (requiredProvider === 'mapbox') { + if (path === '/home') newPath = '/google/home'; + else if (path === '/3d-view') newPath = '/google/3d-view'; + else if (path.startsWith('/driver-view/')) newPath = `/google/driver-view/${path.substring('/driver-view/'.length)}`; + else newPath = '/google/home'; + } else { + if (path === '/google/home') newPath = '/home'; + else if (path === '/google/3d-view') newPath = '/3d-view'; + else if (path.startsWith('/google/driver-view/')) newPath = `/driver-view/${path.substring('/google/driver-view/'.length)}`; + else newPath = '/home'; + } + return ; + } + return ; +}; + const WrappedGoogleHomePage = () => ( @@ -53,34 +75,40 @@ export const App = () => { } /> } /> + path='/home' + element={ } />} + /> } /> + path='/google/home' + element={ } />} + /> } /> + path='/google/3d-view' + element={ } />} + /> } /> + path='/google/driver-view/:vehicleId' + element={ } />} + /> } /> + path='/about' + element={} + /> } /> + path='/guide/:guideId' + element={} + /> } + path="/profile" + element={} /> } + path='/driver-view/:vehicleId' + element={ } />} /> } + path='/3d-view' + element={ } />} /> diff --git a/apps/roadrunner-view/src/components/AboutPage/AboutPage.tsx b/apps/roadrunner-view/src/components/AboutPage/AboutPage.tsx index f157f22..53a77ee 100644 --- a/apps/roadrunner-view/src/components/AboutPage/AboutPage.tsx +++ b/apps/roadrunner-view/src/components/AboutPage/AboutPage.tsx @@ -5,7 +5,8 @@ export function AboutPage() { const navigate = useNavigate(); const goHome = () => { - navigate(`/home`); + const provider = localStorage.getItem('roadrunner_map_provider') || 'google'; + navigate(provider === 'google' ? '/google/home' : '/home'); } return { }); } - navigate('/home'); + const provider = localStorage.getItem('roadrunner_map_provider') || 'google'; + navigate(provider === 'google' ? '/google/home' : '/home'); }, [navigate, vehicleState, homeMapViewState, setHomeMapViewState, goingHome]); // Check if vehicle is absent in active tracking and query historical session if needed @@ -462,7 +463,10 @@ export const DriverViewPage = () => { diff --git a/apps/roadrunner-view/src/components/NavBar/NavBarBrand.tsx b/apps/roadrunner-view/src/components/NavBar/NavBarBrand.tsx index 640fbca..a447381 100644 --- a/apps/roadrunner-view/src/components/NavBar/NavBarBrand.tsx +++ b/apps/roadrunner-view/src/components/NavBar/NavBarBrand.tsx @@ -7,7 +7,10 @@ export const NavBarBrand: React.FC = () => { return (
navigate('/home')} + onClick={() => { + const provider = localStorage.getItem('roadrunner_map_provider') || 'google'; + navigate(provider === 'google' ? '/google/home' : '/home'); + }} style={{ cursor: 'pointer' }} > {