diff --git a/ui/src/Components/NavBar/index.js b/ui/src/Components/NavBar/index.js index 215b9e34c..28f633e68 100644 --- a/ui/src/Components/NavBar/index.js +++ b/ui/src/Components/NavBar/index.js @@ -22,10 +22,6 @@ import "./index.css"; const DesktopIdleTimeout = 1000 * 60 * 3; const MobileIdleTimeout = 1000 * 5; -const NavbarOnResize = function(width, height) { - document.body.style["padding-top"] = `${height + 4}px`; -}; - const NavBar = observer( class NavBar extends Component { static propTypes = { @@ -34,24 +30,63 @@ const NavBar = observer( silenceFormStore: PropTypes.instanceOf(SilenceFormStore).isRequired }; + elementSize = observable( + { + width: 0, + height: 0, + setSize(width, height) { + this.width = width; + this.height = height; + } + }, + { setSize: action } + ); + activityStatus = observable( { idle: false, + className: "visible", setIdle() { this.idle = true; }, setActive() { this.idle = false; + }, + hide() { + this.className = "invisible"; + }, + show() { + this.className = "visible"; } }, { setIdle: action.bound, - setActive: action.bound + setActive: action.bound, + hide: action.bound, + show: action.bound } ); + updateBodyPaddingTop = () => { + const paddingTop = this.activityStatus.idle + ? 0 + : this.elementSize.height + 4; + document.body.style["padding-top"] = `${paddingTop}px`; + }; + onHide = () => { - NavbarOnResize(0, 0); + this.activityStatus.hide(); + this.updateBodyPaddingTop(); + }; + + onShow = () => { + this.updateBodyPaddingTop(); + this.activityStatus.show(); + }; + + onResize = (width, height) => { + this.elementSize.setSize(width, height); + this.updateBodyPaddingTop(); }; render() { @@ -76,12 +111,12 @@ const NavBar = observer( -
+