wip: frontend header & overall status

This commit is contained in:
lyc8503 committed 2023-10-15 02:00:29 +08:00
1 parent cdd43685f2
commit f9212c88a6
13 files changed
+1002 -403

No files matched your search

+8 -39
View File
@@ -1,46 +1,16 @@
import Head from 'next/head'
import { Inter } from 'next/font/google'
const inter = Inter({ subsets: ['latin'] })
import { MonitorState } from '@/uptime.types'
import { KVNamespace } from '@cloudflare/workers-types'
import config from '@/uptime.config'
import OverallStatus from '@/components/OverallStatus'
import Header from '@/components/Header'
export const runtime = 'experimental-edge'
const inter = Inter({ subsets: ['latin'] })
export default function Home({ state }: { state: MonitorState }) {
// Calculate overall status
// TODO: Move this to a component
let downCount = 0
let upCount = 0
for (const monitor of config.monitors) {
if (state.history[monitor.id]?.slice(-1)[0].up) {
upCount += 1
} else {
downCount += 1
}
}
let overallStatus = ""
if (downCount === 0 && upCount === 0) {
overallStatus = "No monitors configured"
}
if (downCount === 0) {
overallStatus = "All systems operational"
}
if (upCount === 0) {
overallStatus = "All systems not operational"
}
if (upCount > 0 && downCount > 0) {
overallStatus = "Some systems not operational"
}
return (
<>
<Head>
@@ -48,11 +18,10 @@ export default function Home({ state }: { state: MonitorState }) {
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<h1>Uptime Flare</h1>
<h2>Current Status: {overallStatus}</h2>
<h2>Last updated on: {state.lastUpdate.toString()}</h2>
<main className={inter.className}>
<Header />
<OverallStatus state={state} />
{
config.monitors.map(monitor => (