refactor: calculation of document titles into another class
This commit is contained in:
@@ -1,21 +1,17 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { Navigate, Route, Routes, useLocation } from "react-router-dom";
|
import { Navigate, Route, Routes, useLocation } from "react-router-dom";
|
||||||
import AppLayout from "./components/AppLayout";
|
import AppLayout from "./components/AppLayout";
|
||||||
|
import DatasetStatusPage from "./pages/DatasetStatus";
|
||||||
import LoginPage from "./pages/Login";
|
import LoginPage from "./pages/Login";
|
||||||
import UploadPage from "./pages/Upload";
|
import UploadPage from "./pages/Upload";
|
||||||
import StatPage from "./pages/Stats";
|
import StatPage from "./pages/Stats";
|
||||||
|
import { getDocumentTitle } from "./utils/documentTitle";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const routeTitles: Record<string, string> = {
|
document.title = getDocumentTitle(location.pathname);
|
||||||
"/login": "Sign In",
|
|
||||||
"/upload": "Upload Dataset",
|
|
||||||
"/stats": "Stats",
|
|
||||||
};
|
|
||||||
|
|
||||||
document.title = routeTitles[location.pathname];
|
|
||||||
}, [location.pathname]);
|
}, [location.pathname]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -24,6 +20,7 @@ function App() {
|
|||||||
<Route path="/" element={<Navigate to="/login" replace />} />
|
<Route path="/" element={<Navigate to="/login" replace />} />
|
||||||
<Route path="/login" element={<LoginPage />} />
|
<Route path="/login" element={<LoginPage />} />
|
||||||
<Route path="/upload" element={<UploadPage />} />
|
<Route path="/upload" element={<UploadPage />} />
|
||||||
|
<Route path="/dataset/:datasetId/status" element={<DatasetStatusPage />} />
|
||||||
<Route path="/stats" element={<StatPage />} />
|
<Route path="/stats" element={<StatPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
15
frontend/src/utils/documentTitle.ts
Normal file
15
frontend/src/utils/documentTitle.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const DEFAULT_TITLE = "Ethnograph View";
|
||||||
|
|
||||||
|
const STATIC_TITLES: Record<string, string> = {
|
||||||
|
"/login": "Sign In",
|
||||||
|
"/upload": "Upload Dataset",
|
||||||
|
"/stats": "Stats",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDocumentTitle = (pathname: string) => {
|
||||||
|
if (pathname.includes("status")) {
|
||||||
|
return "Processing Dataset";
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATIC_TITLES[pathname] ?? DEFAULT_TITLE;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user