Skip to content

Commit

Permalink
Fix telemetry banner
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Nov 18, 2022
1 parent fe3d5df commit 560a65c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/wp-dashboard/src/components/telemetryBanner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,22 +222,29 @@ export function TelemetryBannerContainer(props) {
}

export default function TelemetryBanner() {
const { currentPath } = useRouteHistory(({ state }) => ({
const { currentPath, hasAvailableRoutes } = useRouteHistory(({ state }) => ({
currentPath: state.currentPath,
hasAvailableRoutes: state.availableRoutes.length > 0,
}));
const headerEl = useRef(null);
const [, forceUpdate] = useState(false);

useEffect(() => {
if (!hasAvailableRoutes) {
return;
}

if (
[APP_ROUTES.DASHBOARD, APP_ROUTES.TEMPLATES_GALLERY].includes(currentPath)
) {
headerEl.current = document.getElementById('body-view-options-header');
forceUpdate((value) => !value);
}
}, [currentPath, forceUpdate]);
}, [currentPath, hasAvailableRoutes]);

if (!headerEl.current) {
return null;
}

return headerEl.current
? createPortal(<TelemetryBannerContainer />, headerEl.current)
: null;
return createPortal(<TelemetryBannerContainer />, headerEl.current);
}

0 comments on commit 560a65c

Please sign in to comment.