Files
status/components/OverallStatus.tsx
Michael Kinder fdc16007e3 Restyle the status page in Cottage's brand
The page (pages/, components/, styles/) is rewritten in Cottage's brand, replacing Mantine.
- Brand files: tokens, fonts and component CSS copied from Hearth; logo, pod row, status
  pill and banner ported from the brand handbook.
- Themes: light by default, dark when the OS asks.
- Services: grouped; each has a status pill, uptime and 90 daily bars (30 on phones).
- Bars: each bar has a text label, keyboard navigation and a day card.
- Response-time chart: optional, drawn in brand colours.
- Notices: colour-coded posted notices and planned maintenance.
- Incident history: by month, with the brand's empty state.

The check worker, D1 storage, types and Terraform are untouched, so upstream merges stay
clean. uptime.config.ts lists Cottage's services (website, dashboard, apps in US East).
`npm run dev` shows sample data (?sample=outage|maintenance|empty) since there's no D1.

Deploys are gated on the CLOUDFLARE_DEPLOY repository variable until launch, Wrangler
telemetry is off, and a Check workflow lints, type-checks and builds every pull request.
Removed upstream's issue-translation workflow, funding file and translations.
2026-11-21 14:04:00 -05:00

102 lines
3.1 KiB
TypeScript

import { useEffect, useState } from 'react'
import { MaintenanceConfig, MonitorState, MonitorTarget } from '@/types/config'
import { activeNotices, overallSummary, upcomingNotices } from '@/util/status'
import { PodRow, StatusIcon } from './brand'
import Notice from './Notice'
function useNow() {
const [now, setNow] = useState(() => Math.round(Date.now() / 1000))
useEffect(() => {
const t = setInterval(() => {
if (document.visibilityState === 'visible') setNow(Math.round(Date.now() / 1000))
}, 1000)
return () => clearInterval(t)
}, [])
return now
}
function ago(seconds: number) {
if (seconds < 5) return 'just now'
if (seconds < 90) return `${seconds} seconds ago`
return `${Math.round(seconds / 60)} minutes ago`
}
export default function OverallStatus({
state,
monitors,
maintenances,
}: {
state: MonitorState
monitors: MonitorTarget[]
maintenances: MaintenanceConfig[]
}) {
const now = useNow()
const [openedAt] = useState(now)
const [showUpcoming, setShowUpcoming] = useState(false)
// Reload when the data is more than five minutes old (the worker writes every minute).
useEffect(() => {
if (state.lastUpdate > 0 && now - state.lastUpdate > 300 && now - openedAt > 30) {
window.location.reload()
}
}, [now, state.lastUpdate, openedAt])
const summary = overallSummary(state, monitors, maintenances)
const active = activeNotices(maintenances)
const upcoming = upcomingNotices(maintenances)
const shape = summary.tone === 'success' ? 'dot' : summary.tone === 'neutral' ? 'ring' : summary.title.startsWith('Maintenance') ? 'spin' : 'tri'
return (
<section className="st-hero" aria-labelledby="st-summary">
<PodRow count={5} size={28} />
<h1 id="st-summary" className="ct-h1 st-hero__title">
<span className={`st-hero__icon st-tone--${summary.tone}`}>
<StatusIcon shape={shape} />
</span>
{summary.title}
</h1>
<p className="st-hero__lede">
{state.lastUpdate > 0 ? (
<>
Last checked {ago(now - state.lastUpdate)}
<span className="st-hero__sep" aria-hidden>
·
</span>
checks run every minute
</>
) : (
'The first checks run within a minute of deploying.'
)}
</p>
{active.length > 0 && (
<div className="st-notices">
{active.map((n, i) => (
<Notice key={`a${i}`} notice={n} monitors={monitors} />
))}
</div>
)}
{upcoming.length > 0 && (
<div className="st-upcoming">
<button
type="button"
className="ct-btn ct-btn--quiet ct-btn--sm"
aria-expanded={showUpcoming}
onClick={() => setShowUpcoming(!showUpcoming)}
>
{showUpcoming ? 'Hide' : 'Show'} planned maintenance ({upcoming.length})
</button>
{showUpcoming && (
<div className="st-notices">
{upcoming.map((n, i) => (
<Notice key={`u${i}`} notice={n} monitors={monitors} upcoming />
))}
</div>
)}
</div>
)}
</section>
)
}