eris/ui/App.tsx

47 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

2023-10-05 09:00:51 +00:00
import React, { useEffect } from "react";
import { Route, Routes } from "react-router-dom";
2023-10-23 00:39:01 +00:00
import { AdminsPage } from "./AdminsPage.tsx";
2023-10-05 09:00:51 +00:00
import { AppHeader } from "./AppHeader.tsx";
import { QueuePage } from "./QueuePage.tsx";
import { SettingsPage } from "./SettingsPage.tsx";
2023-10-13 11:47:57 +00:00
import { StatsPage } from "./StatsPage.tsx";
import { WorkersPage } from "./WorkersPage.tsx";
2023-10-23 00:39:01 +00:00
import { fetchApi, handleResponse } from "./apiClient.ts";
import { useLocalStorage } from "./useLocalStorage.ts";
2023-10-05 09:00:51 +00:00
export function App() {
// store session ID in the local storage
2023-10-23 00:39:01 +00:00
const [sessionId, setSessionId] = useLocalStorage("sessionId");
2023-10-05 09:00:51 +00:00
// 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);
},
);
2023-10-05 09:00:51 +00:00
}
}, [sessionId]);
return (
<>
<AppHeader
className="self-stretch"
sessionId={sessionId}
2023-10-23 00:39:01 +00:00
onLogOut={() => setSessionId(null)}
2023-10-05 09:00:51 +00:00
/>
<div className="self-center w-full max-w-screen-md flex flex-col items-stretch gap-4 p-4">
<Routes>
2023-10-13 11:47:57 +00:00
<Route path="/" element={<StatsPage />} />
2023-10-23 00:39:01 +00:00
<Route path="/admins" element={<AdminsPage sessionId={sessionId} />} />
2023-10-13 11:47:57 +00:00
<Route path="/workers" element={<WorkersPage sessionId={sessionId} />} />
2023-10-05 09:00:51 +00:00
<Route path="/queue" element={<QueuePage />} />
<Route path="/settings" element={<SettingsPage sessionId={sessionId} />} />
</Routes>
</div>
</>
);
}