Skip to content

Commit

Permalink
fix: Maintain full title name when reloading page
Browse files Browse the repository at this point in the history
  • Loading branch information
freshavocado7 committed May 7, 2024
1 parent c461c49 commit f020936
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
17 changes: 4 additions & 13 deletions frontend/src/components/Breadcrumbs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ export const Breadcrumbs = () => {
const location = useLocation();
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 @@ -57,15 +49,14 @@ export const Breadcrumbs = () => {
labels[to] = pathnames[i];
}
}
console.log(labels);

setBreadcrumbLabels(labels);
const lastBreadcrumb = Object.values(labels).pop();
document.title = `${lastBreadcrumb} | ${initialTitle} Model Explorer`;
const modelName = Object.values(labels)[0];
const instanceName = Object.values(labels).pop();
document.title = `${instanceName} - ${modelName} - Model Explorer`;
};

updateLabels();
}, [location, initialTitle]);
}, [location, document.title]);

const visible_pathnames = [
breadcrumbLabels["/"],
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/HomeView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +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
document.title = `${data.title} - Model Explorer`;
} catch (err) {
setError("Failed to fetch model info: " + err.message);
}
Expand Down

0 comments on commit f020936

Please sign in to comment.