import { useEffect, useState } from "react"; import { Navigate, Route, Routes, useNavigate } from "react-router-dom"; import { api, applySession, clearSession, isDirty } from "./api.js"; import { SessionContext } from "./session.js"; import { Login } from "./pages/Login.jsx"; import { Shell } from "./pages/Shell.jsx"; import { Overview } from "./pages/Overview.jsx"; import { CaseDetail } from "./pages/Cases.jsx"; import { MatterDetail } from "./pages/Matters.jsx"; import { LibraryLayout } from "./library/LibraryLayout.jsx"; import { EntryPage, RoomPage, RoomsPage } from "./library/Pages.jsx"; import { Search } from "./pages/Search.jsx"; import { Sources } from "./pages/Sources.jsx"; import { ConnectorConfig } from "./sources/connector-config.jsx"; import { Account, ForcedPasswordChange } from "./admin/Account.jsx"; import { AdminEvents } from "./admin/Admin.jsx"; import { InviteAccept } from "./admin/InviteAccept.jsx"; import { AdminTeam, Team } from "./admin/Team.jsx"; import { UserDetail, Users } from "./admin/Users.jsx"; import { Work } from "./pages/Work.jsx"; import { Settings } from "./pages/Settings.jsx"; import { Reader } from "./pages/Reader.jsx"; import { appTitle, isDevelopment } from "./environment.js"; function EnvironmentBanner() { useEffect(() => { document.title = appTitle; if (!isDevelopment) return; document.querySelector('meta[name="theme-color"]')?.setAttribute("content", "#8a5a12"); }, []); if (!isDevelopment) return null; return
Entwicklungsumgebung
; } export function App() { const [session, setSession] = useState(undefined); const navigate = useNavigate(); useEffect(() => { let active = true; api("/api/v1/auth/session") .then((data) => { if (!active) return; applySession(data); setSession(data); }) .catch(() => { if (!active) return; clearSession(); setSession(null); }); return () => { active = false; }; }, []); useEffect(() => { // The server moved the session to another data room (removed, archived). Reload the session. function onScopeChanged() { api("/api/v1/auth/session") .then((data) => { applySession(data); setSession(data); navigate("/"); }) .catch(() => {}); } window.addEventListener("tsumugu:scope-changed", onScopeChanged); return () => window.removeEventListener("tsumugu:scope-changed", onScopeChanged); }, []); async function refresh() { const data = await api("/api/v1/auth/session"); applySession(data); setSession(data); return data; } async function changeScope(next) { if (isDirty() && !window.confirm("Ungespeicherte Eingaben verwerfen und den Datenraum wechseln?")) { return; } const data = await api("/api/v1/auth/session/scope", { method: "POST", body: { kind: next.kind, id: next.id } }); applySession(data); setSession(data); navigate("/"); } async function logout() { try { await api("/api/v1/auth/logout", { method: "POST" }); } catch { /* Die lokale Sitzung endet auch, wenn der Server schon abgemeldet hat. */ } clearSession(); setSession(null); navigate("/login"); } if (session === undefined) { return (Tsumugu wird geladen …