forked from pinks/eris
1
0
Fork 0
nyx/ui/App.tsx

45 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) {
2023-10-08 21:23:54 +00:00
fetchApi("sessions", "POST", {}).then(handleResponse).then((session) => {
2023-10-05 09:00:51 +00:00
console.log("Initialized session", session.id);
setSessionId(session.id);
});
}
}, [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>
</>
);
}