diff --git a/src-web/components/AppRouter.tsx b/src-web/components/AppRouter.tsx index 06504696..f3d61137 100644 --- a/src-web/components/AppRouter.tsx +++ b/src-web/components/AppRouter.tsx @@ -3,11 +3,11 @@ import { routePaths, useAppRoutes } from '../hooks/useAppRoutes'; import { useRecentRequests } from '../hooks/useRecentRequests'; import { useRequests } from '../hooks/useRequests'; import { GlobalHooks } from './GlobalHooks'; -import RouteError from './RouteError'; import Workspace from './Workspace'; import Workspaces from './Workspaces'; import { DialogProvider } from './DialogContext'; -import { useRecentEnvironments } from '../hooks/useRecentEnvironments'; +import { useActiveEnvironmentId } from '../hooks/useActiveEnvironmentId'; +import RouteError from './RouteError'; const router = createBrowserRouter([ { @@ -48,7 +48,7 @@ export function AppRouter() { function WorkspaceOrRedirect() { const recentRequests = useRecentRequests(); - const recentEnvironments = useRecentEnvironments(); + const activeEnvironmentId = useActiveEnvironmentId(); const requests = useRequests(); const request = requests.find((r) => r.id === recentRequests[0]); const routes = useAppRoutes(); @@ -57,8 +57,8 @@ function WorkspaceOrRedirect() { return ; } - const environmentId = recentEnvironments[0]; const { id: requestId, workspaceId } = request; + const environmentId = activeEnvironmentId ?? undefined; return ( ({ key, namespace, fallback }); + if (pathname != null) { + window.location.replace(pathname); + } + return; + } + + window.addEventListener('pushstate', async () => { + const { pathname: value } = window.location; + await setKeyValue({ key, namespace, value }); + }); +} diff --git a/src-web/main.tsx b/src-web/main.tsx index 7ffce4b8..aeb05978 100644 --- a/src-web/main.tsx +++ b/src-web/main.tsx @@ -4,10 +4,17 @@ import { App } from './components/App'; import { getKeyValue } from './lib/keyValueStore'; import { getPreferredAppearance, setAppearance } from './lib/theme/window'; import './main.css'; +import { initPathnamePersistance } from './lib/initPathnamePersistance'; -setAppearance(await getKeyValue({ key: 'appearance', fallback: getPreferredAppearance() })); +await initPathnamePersistance(); + +setAppearance( + await getKeyValue({ + key: 'appearance', + fallback: getPreferredAppearance(), + }), +); -// root holds our app's root DOM Element: createRoot(document.getElementById('root') as HTMLElement).render(