2020-11-20 17:05:13 +01:00
|
|
|
import { Store } from 'laco'
|
|
|
|
import { useStore } from 'laco-react'
|
2020-11-08 13:56:02 +01:00
|
|
|
import Head from 'flareact/head'
|
|
|
|
|
2020-11-21 22:01:28 +01:00
|
|
|
import { getKVMonitors, useKeyPress } from '../src/functions/helpers'
|
2020-11-08 13:56:02 +01:00
|
|
|
import config from '../config.yaml'
|
2020-11-20 17:05:13 +01:00
|
|
|
import MonitorCard from '../src/components/monitorCard'
|
2020-11-17 00:50:19 +01:00
|
|
|
import MonitorFilter from '../src/components/monitorFilter'
|
2020-11-20 17:05:13 +01:00
|
|
|
import MonitorStatusHeader from '../src/components/monitorStatusHeader'
|
|
|
|
import ThemeSwitcher from '../src/components/themeSwitcher'
|
2020-11-17 00:50:19 +01:00
|
|
|
|
2020-11-20 17:05:13 +01:00
|
|
|
const MonitorStore = new Store({
|
|
|
|
monitors: config.monitors,
|
|
|
|
visible: config.monitors,
|
|
|
|
activeFilter: false,
|
|
|
|
})
|
2020-11-17 00:50:19 +01:00
|
|
|
|
2020-11-20 17:05:13 +01:00
|
|
|
const filterByTerm = (term) =>
|
|
|
|
MonitorStore.set((state) => ({
|
|
|
|
visible: state.monitors.filter((monitor) =>
|
|
|
|
monitor.name.toLowerCase().includes(term),
|
|
|
|
),
|
|
|
|
}))
|
2020-11-08 13:56:02 +01:00
|
|
|
|
|
|
|
export async function getEdgeProps() {
|
|
|
|
// get KV data
|
2020-11-21 22:01:28 +01:00
|
|
|
const kvMonitors = await getKVMonitors()
|
2020-11-08 13:56:02 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
config,
|
2020-11-21 22:01:28 +01:00
|
|
|
kvMonitors: kvMonitors ? kvMonitors.monitors : {},
|
|
|
|
kvMonitorsLastUpdate: kvMonitors ? kvMonitors.lastUpdate : {},
|
2020-11-08 13:56:02 +01:00
|
|
|
},
|
|
|
|
// Revalidate these props once every x seconds
|
|
|
|
revalidate: 5,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 22:01:28 +01:00
|
|
|
export default function Index({ config, kvMonitors, kvMonitorsLastUpdate }) {
|
2020-11-17 00:50:19 +01:00
|
|
|
const state = useStore(MonitorStore)
|
|
|
|
const slash = useKeyPress('/')
|
|
|
|
|
2020-11-08 13:56:02 +01:00
|
|
|
return (
|
2020-11-20 17:05:13 +01:00
|
|
|
<div className="min-h-screen">
|
2020-11-08 13:56:02 +01:00
|
|
|
<Head>
|
|
|
|
<title>{config.settings.title}</title>
|
2020-11-20 17:05:13 +01:00
|
|
|
<link rel="stylesheet" href="./style.css" />
|
|
|
|
<script>
|
|
|
|
{`
|
|
|
|
function setTheme(theme) {
|
|
|
|
document.documentElement.classList.remove("dark", "light")
|
|
|
|
document.documentElement.classList.add(theme)
|
|
|
|
localStorage.theme = theme
|
|
|
|
}
|
|
|
|
(() => {
|
|
|
|
const query = window.matchMedia("(prefers-color-scheme: dark)")
|
|
|
|
query.addListener(() => {
|
|
|
|
setTheme(query.matches ? "dark" : "light")
|
|
|
|
})
|
|
|
|
if (["dark", "light"].includes(localStorage.theme)) {
|
|
|
|
setTheme(localStorage.theme)
|
|
|
|
} else {
|
|
|
|
setTheme(query.matches ? "dark" : "light")
|
|
|
|
}
|
|
|
|
})()
|
|
|
|
`}
|
|
|
|
</script>
|
2020-11-08 13:56:02 +01:00
|
|
|
</Head>
|
2020-11-20 17:05:13 +01:00
|
|
|
<div className="container mx-auto px-4">
|
|
|
|
<div className="flex flex-row justify-between items-center p-4">
|
|
|
|
<div className="flex flex-row items-center">
|
|
|
|
<img className="h-8 w-auto" src={config.settings.logo} />
|
|
|
|
<h1 className="ml-4 text-3xl">{config.settings.title}</h1>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-row items-center">
|
|
|
|
{typeof window !== 'undefined' && <ThemeSwitcher />}
|
|
|
|
<MonitorFilter active={slash} callback={filterByTerm} />
|
|
|
|
</div>
|
2020-11-17 00:50:19 +01:00
|
|
|
</div>
|
2020-11-21 22:01:28 +01:00
|
|
|
<MonitorStatusHeader kvMonitorsLastUpdate={kvMonitorsLastUpdate} />
|
2020-11-17 00:50:19 +01:00
|
|
|
{state.visible.map((monitor, key) => {
|
2020-11-08 13:56:02 +01:00
|
|
|
return (
|
2020-11-20 17:05:13 +01:00
|
|
|
<MonitorCard
|
|
|
|
key={key}
|
|
|
|
monitor={monitor}
|
|
|
|
data={kvMonitors[monitor.id]}
|
|
|
|
/>
|
2020-11-08 13:56:02 +01:00
|
|
|
)
|
|
|
|
})}
|
2020-11-20 17:05:13 +01:00
|
|
|
<div className="flex flex-row justify-between mt-4 text-sm">
|
2020-11-08 13:56:02 +01:00
|
|
|
<div>
|
|
|
|
Powered by{' '}
|
|
|
|
<a href="https://workers.cloudflare.com/" target="_blank">
|
|
|
|
Cloudflare Workers{' '}
|
|
|
|
</a>
|
|
|
|
&{' '}
|
|
|
|
<a href="https://flareact.com/" target="_blank">
|
|
|
|
Flareact{' '}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<a
|
2020-11-14 02:57:06 +01:00
|
|
|
href="https://github.com/eidam/cf-workers-status-page"
|
2020-11-08 13:56:02 +01:00
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
Get Your Status Page
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|