From b194429958132a39ea491ca2c83e87014b4672c9 Mon Sep 17 00:00:00 2001 From: Ibukun Dairo Date: Mon, 22 Jun 2020 15:33:23 +0100 Subject: [PATCH] Make status page responsive --- status-page/public/stylesheets/style.css | 39 +++++++++++-- status-page/src/components/UptimeGraphs.js | 65 +++++++++++++++++++++- 2 files changed, 96 insertions(+), 8 deletions(-) diff --git a/status-page/public/stylesheets/style.css b/status-page/public/stylesheets/style.css index dd0eb3a94a..282be2cf4d 100755 --- a/status-page/public/stylesheets/style.css +++ b/status-page/public/stylesheets/style.css @@ -23,7 +23,6 @@ body { } .page-main-wrapper { - width: 100%; min-height: 100vh; max-height: fit-content; display: flex; @@ -33,8 +32,8 @@ body { /* .innernew responsive styles */ .innernew { - width: 605px; margin: auto; + padding: 0 8px; } /* end */ @@ -81,9 +80,12 @@ div.block-chart { width: 101%; /* IE overflow fix */ } +div.block-chart::-webkit-scrollbar { + height: 0px; +} + div.block-chart div.bar { - float: left; - position: relative; + display: inline-block; height: 100%; width: 4px; @@ -104,8 +106,6 @@ div.block-chart { } div.block-chart div.bar.empty { - float: left; - position: relative; height: 100%; width: 4px; @@ -232,6 +232,8 @@ div.block-chart { .banner { width: 100%; + height: 250px; + object-fit: cover; } /******* Content *******/ @@ -1014,4 +1016,29 @@ margin-left:10px; margin: 0 auto; left: 0; padding-bottom: 10px; +} + +.scroll-content { + height: 100%; +} + +@media screen and (max-width: 500px) { + .box-inner { + padding: 16px; + } + + .largestatus { + padding: 0 16px; + padding-left: 64px; + } + + .status-bubble { + left: 16px; + } +} + +@media screen and (max-width: 420px) { + .feed-item div.message { + width: auto !important; + } } \ No newline at end of file diff --git a/status-page/src/components/UptimeGraphs.js b/status-page/src/components/UptimeGraphs.js index 75446bad8c..9bb09799c2 100755 --- a/status-page/src/components/UptimeGraphs.js +++ b/status-page/src/components/UptimeGraphs.js @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React, { Component, createRef } from 'react'; import PropTypes from 'prop-types'; import BlockChart from './BlockChart'; import moment from 'moment'; @@ -80,7 +80,29 @@ const calculateTime = (statuses, start, range) => { return { timeBlock, uptimePercent: (totalUptime / totalTime) * 100 }; }; +function debounce(fn, ms) { + let timer; + // eslint-disable-next-line no-unused-vars + return _ => { + clearTimeout(timer); + // eslint-disable-next-line no-unused-vars + timer = setTimeout(_ => { + timer = null; + fn.apply(this, arguments); + }, ms); + }; +} + class UptimeGraphs extends Component { + constructor(props) { + super(props); + + this.container = createRef(); + this.scrollWrapper = createRef(); + this.scrollContent = createRef(); + this.resizeHandler = this.resizeHandler.bind(this); + } + componentDidMount() { const { monitor } = this.props; @@ -94,6 +116,9 @@ class UptimeGraphs extends Component { endDate ); } + + this.resizeHandler(); + window.addEventListener('resize', debounce(this.resizeHandler, 100)); } componentDidUpdate(prevProps) { @@ -113,6 +138,33 @@ class UptimeGraphs extends Component { } } + componentWillUnmount() { + window.removeEventListener('resize', debounce(this.resizeHandler, 100)); + } + + resizeHandler() { + // block chart scroll wrapper + const scrollWrapper = this.scrollWrapper.current; + scrollWrapper.style.width = 'auto'; + + // block chart scroll content + const scrollContent = this.scrollContent.current; + scrollContent.style.width = 'auto'; + + // uptime graph container + const container = this.container.current; + + setTimeout(() => { + // adjust width + scrollWrapper.style.width = `${container.clientWidth}px`; + scrollContent.style.width = 'max-content'; + + // scroll to end of chart + scrollWrapper.scrollLeft = + scrollContent.clientWidth - scrollWrapper.clientWidth; + }, 400); + } + render() { const { monitorState, @@ -185,6 +237,7 @@ class UptimeGraphs extends Component {
@@ -223,7 +276,15 @@ class UptimeGraphs extends Component { {upDays > 1 ? 's' : ''}
-
{block}
+
+
+ {block} +
+
); }