import React, { useEffect } from "react"; import { Route, Routes } from "react-router-dom"; import { AdminsPage } from "./AdminsPage.tsx"; import { AppHeader } from "./AppHeader.tsx"; import { QueuePage } from "./QueuePage.tsx"; import { SettingsPage } from "./SettingsPage.tsx"; import { StatsPage } from "./StatsPage.tsx"; import { WorkersPage } from "./WorkersPage.tsx"; import { fetchApi, handleResponse } from "./apiClient.ts"; import { useLocalStorage } from "./useLocalStorage.ts"; import { DisclaimerPage } from "./DisclaimerPage.tsx"; export function App() { // store session ID in the local storage const [sessionId, setSessionId] = useLocalStorage("sessionId"); // initialize a new session when there is no session ID useEffect(() => { if (!sessionId) { fetchApi("/sessions", { method: "POST" }).then((resp) => resp).then(handleResponse).then( (session) => { console.log("Initialized session", session.id); setSessionId(session.id); }, ); } }, [sessionId]); return ( <> setSessionId(null)} />
} /> } /> } /> } /> } /> } />
); }