mirror of
https://github.com/tormachris/cf-workers-status-page.git
synced 2024-11-23 22:45:43 +01:00
refactor: move status header to its own component
This commit is contained in:
parent
eff367f15e
commit
61f788df1f
@ -9,6 +9,7 @@ import {
|
||||
|
||||
import config from '../config.yaml'
|
||||
import MonitorStatusLabel from '../src/components/monitorStatusLabel'
|
||||
import MonitorStatusHeader from '../src/components/monitorStatusHeader'
|
||||
|
||||
export async function getEdgeProps() {
|
||||
// get KV data
|
||||
@ -68,24 +69,10 @@ export default function Index({
|
||||
/>
|
||||
{config.settings.title}
|
||||
</h1>
|
||||
<div
|
||||
className={`ui inverted segment ${
|
||||
monitorsOperational ? 'green' : 'yellow'
|
||||
}`}
|
||||
>
|
||||
<div className="horizontal flex between">
|
||||
<div className="ui marginless header black-text">
|
||||
{monitorsOperational
|
||||
? config.settings.allmonitorsOperational
|
||||
: config.settings.notAllmonitorsOperational}
|
||||
</div>
|
||||
{kvLastUpdate.metadata && typeof window !== 'undefined' && (
|
||||
<div className="black-text">
|
||||
checked {Math.round((Date.now() - kvLastUpdate.value) / 1000)} sec ago (from {kvLastUpdate.metadata.loc})
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<MonitorStatusHeader
|
||||
operational={monitorsOperational}
|
||||
lastUpdate={kvLastUpdate}
|
||||
/>
|
||||
{config.monitors.map((monitor, key) => {
|
||||
return (
|
||||
<div key={key} className="ui segment">
|
||||
|
31
src/components/monitorStatusHeader.js
Normal file
31
src/components/monitorStatusHeader.js
Normal file
@ -0,0 +1,31 @@
|
||||
import config from '../../config.yaml'
|
||||
|
||||
export default function MonitorStatusHeader({ operational, lastUpdate }) {
|
||||
let backgroundColor = 'green'
|
||||
let headerText = config.settings.allmonitorsOperational
|
||||
let textColor = 'black'
|
||||
|
||||
if (!operational) {
|
||||
backgroundColor = 'yellow'
|
||||
headerText = config.settings.notAllmonitorsOperational
|
||||
}
|
||||
|
||||
const lastCheckAgo = Math.round((Date.now() - lastUpdate.value) / 1000)
|
||||
|
||||
return (
|
||||
<div className={`ui inverted segment ${backgroundColor}`}>
|
||||
<div className="horizontal flex between">
|
||||
<div className={`ui marginless header ${textColor}-text`}>
|
||||
{headerText}
|
||||
</div>
|
||||
{
|
||||
lastUpdate.metadata && typeof window !== 'undefined' && (
|
||||
<div className={`${textColor}-text`}>
|
||||
checked {lastCheckAgo} sec ago (from {lastUpdate.metadata.loc})
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user