Fastify/Postgres backend + React frontend matching the stack's app conventions, plus a hand-rolled RFC 4791 CalDAV server (caldav-adapter turned out Koa-only in practice) so calendars subscribe as genuine two-way sync in Apple/Google/Outlook. v1 scope: multiple colour-coded calendars, department/staff event tagging via live Workforce lookups, month/week/day/list views, dashboard, file attachments, activity log, and an auto-synced UK bank holidays calendar. Verified end-to-end locally against real Postgres: REST CRUD, CalDAV discovery/PROPFIND/REPORT/PUT/sync-collection, all-day date handling, system-calendar write protection, and activity logging across both the web and CalDAV write paths. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { useEffect, useState } from 'react'
|
|
|
|
const POLL_MS = 2 * 60 * 1000
|
|
|
|
export function useVersionCheck(healthUrl: string) {
|
|
const [updateAvailable, setUpdateAvailable] = useState(false)
|
|
|
|
useEffect(() => {
|
|
let seenVersion: string | null = null
|
|
|
|
async function check() {
|
|
try {
|
|
const res = await fetch(healthUrl, { cache: 'no-store' })
|
|
if (!res.ok) return
|
|
const data = await res.json()
|
|
const v: string | undefined = data.version
|
|
if (!v) return
|
|
if (seenVersion === null) {
|
|
seenVersion = v
|
|
} else if (v !== seenVersion) {
|
|
setUpdateAvailable(true)
|
|
}
|
|
} catch {
|
|
// network error — skip silently
|
|
}
|
|
}
|
|
|
|
check()
|
|
const interval = setInterval(check, POLL_MS)
|
|
|
|
function onVisible() {
|
|
if (document.visibilityState === 'visible') check()
|
|
}
|
|
document.addEventListener('visibilitychange', onVisible)
|
|
|
|
return () => {
|
|
clearInterval(interval)
|
|
document.removeEventListener('visibilitychange', onVisible)
|
|
}
|
|
}, [healthUrl])
|
|
|
|
return updateAvailable
|
|
}
|