Skip to content

Commit

Permalink
feat: Update page title based on current view
Browse files Browse the repository at this point in the history
  • Loading branch information
freshavocado7 committed May 6, 2024
1 parent 5729f4a commit c461c49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frontend/src/components/Breadcrumbs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export const Breadcrumbs = () => {
const [breadcrumbLabels, setBreadcrumbLabels] = useState({});
const pathnames = location.pathname.split("/").filter((x) => x);
const [error, setError] = useState(null);
const [initialTitle, setInitialTitle] = useState("");

useEffect(() => {
if (!initialTitle) {
setInitialTitle(document.title);
}
}, [initialTitle]);

const fetchModelInfo = async () => {
const response = await fetch(API_BASE_URL + `/model-info`);
Expand Down Expand Up @@ -53,10 +60,12 @@ export const Breadcrumbs = () => {
console.log(labels);

setBreadcrumbLabels(labels);
const lastBreadcrumb = Object.values(labels).pop();
document.title = `${lastBreadcrumb} | ${initialTitle} Model Explorer`;
};

updateLabels();
}, [location]);
}, [location, initialTitle]);

const visible_pathnames = [
breadcrumbLabels["/"],
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/HomeView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const HomeView = () => {
const response = await fetch(API_BASE_URL + "/model-info");
const data = await response.json();
setModelInfo(data);
document.title = `${data.title} Model Explorer`; // Closes #8, not related with screen size changes
} catch (err) {
setError("Failed to fetch model info: " + err.message);
}
Expand Down

0 comments on commit c461c49

Please sign in to comment.