Skip to content

Commit

Permalink
Minor fix to how ApplicationView handles route change
Browse files Browse the repository at this point in the history
  • Loading branch information
kravets-levko committed Jan 10, 2020
1 parent 8bb6c6d commit e4350f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions client/app/components/ApplicationArea/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useCallback } from "react";
import React, { useState, useEffect } from "react";
import ApplicationHeader from "@/components/ApplicationHeader";

import routes from "@/pages";
Expand Down Expand Up @@ -37,16 +37,22 @@ export default function ApplicationArea() {
// Better solution is either to move header to each page or create some global state for currentUser/clientConfig/etc.
const [currentRoute, setCurrentRoute] = useState(null);

const handleRouteChange = useCallback(route => {
setCurrentRoute(route);
route = route || { authenticated: true };
const layout = selectLayout(route);
setShowHeader(layout.showHeader);
document.body.className = layout.bodyClass;
useEffect(() => {
const route = currentRoute || { authenticated: true };

if (route.title) {
document.title = route.title;
}
}, []);

const layout = selectLayout(route);
setShowHeader(layout.showHeader);
if (layout.bodyClass) {
document.body.classList.toggle(layout.bodyClass, true);
return () => {
document.body.classList.toggle(layout.bodyClass, false);
};
}
}, [currentRoute]);

useEffect(() => {
document.body.addEventListener("click", handleNavigationIntent, false);
Expand All @@ -59,7 +65,7 @@ export default function ApplicationArea() {
return (
<>
{currentRoute && showHeader && <ApplicationHeader currentRoute={currentRoute} />}
<Router routes={routes} onRouteChange={handleRouteChange} />
<Router routes={routes} onRouteChange={setCurrentRoute} />
</>
);
}
2 changes: 1 addition & 1 deletion client/app/pages/dashboards/useDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function getRefreshRateFromUrl() {
function useFullscreenHandler() {
const [fullscreen, setFullscreen] = useState(has(location.search, "fullscreen"));
useEffect(() => {
document.querySelector("body").classList.toggle("headless", fullscreen);
document.body.classList.toggle("headless", fullscreen);
location.setSearch({ fullscreen: fullscreen ? true : null });
}, [fullscreen]);

Expand Down

0 comments on commit e4350f0

Please sign in to comment.