Compare commits
No commits in common. "52af5f86bc099280ecfd5aed65e2d53ca2b75487" and "331d15ac88a8f2f765ddea5be495742db3a561a9" have entirely different histories.
52af5f86bc
...
331d15ac88
7 changed files with 14 additions and 209 deletions
|
|
@ -10,7 +10,6 @@ import { activityRoutes } from './routes/activity.js'
|
||||||
import { eventsRoutes } from './routes/events.js'
|
import { eventsRoutes } from './routes/events.js'
|
||||||
|
|
||||||
const app = Fastify({ logger: true, trustProxy: true })
|
const app = Fastify({ logger: true, trustProxy: true })
|
||||||
const startedAt = Date.now()
|
|
||||||
|
|
||||||
await app.register(cookie)
|
await app.register(cookie)
|
||||||
await app.register(cors, {
|
await app.register(cors, {
|
||||||
|
|
@ -18,7 +17,7 @@ await app.register(cors, {
|
||||||
credentials: true,
|
credentials: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/health', async () => ({ status: 'healthy', version: process.env.BUILD_VERSION || String(startedAt) }))
|
app.get('/health', async () => ({ status: 'healthy' }))
|
||||||
|
|
||||||
await app.register(roomRoutes)
|
await app.register(roomRoutes)
|
||||||
await app.register(taskRoutes)
|
await app.register(taskRoutes)
|
||||||
|
|
|
||||||
|
|
@ -89,10 +89,6 @@ export function classifyRoom(site, allBookings, viewDate, yesterday, tomorrow, o
|
||||||
// Determine flow type
|
// Determine flow type
|
||||||
let flowType = 'vacant'
|
let flowType = 'vacant'
|
||||||
|
|
||||||
// True when primaryBooking is a historical depart-only record (set below) rather
|
|
||||||
// than a booking that actually occupies viewDate — the room was vacant that night.
|
|
||||||
let isPastDepartureRecord = false
|
|
||||||
|
|
||||||
if (primaryBooking) {
|
if (primaryBooking) {
|
||||||
const status = (primaryBooking.booking_status || '').toLowerCase()
|
const status = (primaryBooking.booking_status || '').toLowerCase()
|
||||||
if (status === 'blocked') {
|
if (status === 'blocked') {
|
||||||
|
|
@ -117,7 +113,6 @@ export function classifyRoom(site, allBookings, viewDate, yesterday, tomorrow, o
|
||||||
} else if (effectiveDeparting && opts.past) {
|
} else if (effectiveDeparting && opts.past) {
|
||||||
primaryBooking = effectiveDeparting
|
primaryBooking = effectiveDeparting
|
||||||
flowType = 'depart'
|
flowType = 'depart'
|
||||||
isPastDepartureRecord = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const arrivalDate = primaryBooking ? toDateStr(primaryBooking.booking_arrival) : null
|
const arrivalDate = primaryBooking ? toDateStr(primaryBooking.booking_arrival) : null
|
||||||
|
|
@ -163,10 +158,7 @@ export function classifyRoom(site, allBookings, viewDate, yesterday, tomorrow, o
|
||||||
flow_type: flowType,
|
flow_type: flowType,
|
||||||
booking: primaryBooking,
|
booking: primaryBooking,
|
||||||
|
|
||||||
// A past-departure record only marks that a checkout happened on viewDate — it
|
spans_previous: isVacantFlow
|
||||||
// never occupied the night before viewDate, so it must not merge with the prior
|
|
||||||
// card the way a booking that's still actively occupying viewDate would.
|
|
||||||
spans_previous: (isVacantFlow || isPastDepartureRecord)
|
|
||||||
? prevVacant
|
? prevVacant
|
||||||
: !!primaryBooking && !!arrivalDate && arrivalDate < viewDate,
|
: !!primaryBooking && !!arrivalDate && arrivalDate < viewDate,
|
||||||
spans_next: isVacantFlow ? nextVacant : spansNext,
|
spans_next: isVacantFlow ? nextVacant : spansNext,
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@
|
||||||
<meta name="mobile-web-app-capable" content="yes" />
|
<meta name="mobile-web-app-capable" content="yes" />
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||||
<meta name="apple-mobile-web-app-title" content="Room Planner" />
|
|
||||||
<link rel="apple-touch-icon" href="/room-planner/icons/icon-192.png" />
|
|
||||||
<meta name="theme-color" content="#2d6a4f" />
|
<meta name="theme-color" content="#2d6a4f" />
|
||||||
<title>Room Planner</title>
|
<title>Room Planner</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,11 @@
|
||||||
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'
|
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'
|
||||||
import AuthGate from './components/AuthGate'
|
import AuthGate from './components/AuthGate'
|
||||||
import { UpdateBanner } from './components/UpdateBanner'
|
|
||||||
import IosInstallHint from './components/IosInstallHint'
|
|
||||||
import { useVersionCheck } from './hooks/useVersionCheck'
|
|
||||||
import Layout from './components/Layout'
|
import Layout from './components/Layout'
|
||||||
import Planner from './pages/Planner'
|
import Planner from './pages/Planner'
|
||||||
import Settings from './pages/Settings'
|
import Settings from './pages/Settings'
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const updateAvailable = useVersionCheck('/room-planner/health')
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<BrowserRouter basename="/room-planner">
|
<BrowserRouter basename="/room-planner">
|
||||||
<AuthGate>
|
<AuthGate>
|
||||||
<Layout>
|
<Layout>
|
||||||
|
|
@ -23,8 +18,5 @@ export default function App() {
|
||||||
</Layout>
|
</Layout>
|
||||||
</AuthGate>
|
</AuthGate>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
<UpdateBanner visible={updateAvailable} />
|
|
||||||
<IosInstallHint />
|
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { Share, ExternalLink, X } from 'lucide-react'
|
|
||||||
|
|
||||||
function isIos() {
|
|
||||||
return /iPad|iPhone|iPod/.test(navigator.userAgent) ||
|
|
||||||
// iPadOS 13+ reports as 'MacIntel' but has touch support, unlike a real Mac
|
|
||||||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isStandalone() {
|
|
||||||
return window.matchMedia('(display-mode: standalone)').matches ||
|
|
||||||
(window.navigator as unknown as { standalone?: boolean }).standalone === true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Safari's UA also matches "Safari", so this checks for the other iOS
|
|
||||||
// browsers/in-app webviews that spoof it — none of them can add to the
|
|
||||||
// home screen; only Safari itself can.
|
|
||||||
function isNonSafariIosBrowser() {
|
|
||||||
return /CriOS|FxiOS|EdgiOS|OPiOS|mercury|GSA|DuckDuckGo|Instagram|FBAN|FBAV|Line\//.test(navigator.userAgent)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* iOS has no `beforeinstallprompt` API — Safari never fires it, so the
|
|
||||||
* portal's Install button (?install=1) does nothing there. This shows the
|
|
||||||
* manual steps instead: Share -> Add to Home Screen in Safari, or a prompt
|
|
||||||
* to switch to Safari first if the page was opened in another browser/app.
|
|
||||||
*/
|
|
||||||
export default function IosInstallHint() {
|
|
||||||
const [mode, setMode] = useState<'safari' | 'other' | null>(null)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isIos() || isStandalone()) return
|
|
||||||
if (!new URLSearchParams(window.location.search).has('install')) return
|
|
||||||
setMode(isNonSafariIosBrowser() ? 'other' : 'safari')
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
if (!mode) return null
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
position: 'fixed', inset: 0, zIndex: 9999,
|
|
||||||
background: 'rgba(15,15,32,0.55)',
|
|
||||||
display: 'flex', alignItems: 'flex-end', justifyContent: 'center',
|
|
||||||
padding: '0 16px 24px',
|
|
||||||
}}>
|
|
||||||
<div style={{
|
|
||||||
position: 'relative',
|
|
||||||
width: '100%', maxWidth: '360px',
|
|
||||||
background: 'var(--card-bg)', borderRadius: 'var(--radius)',
|
|
||||||
border: '1px solid var(--card-border)', boxShadow: 'var(--shadow-md)',
|
|
||||||
padding: '20px', textAlign: 'center',
|
|
||||||
}}>
|
|
||||||
<button
|
|
||||||
onClick={() => setMode(null)}
|
|
||||||
aria-label="Dismiss"
|
|
||||||
style={{
|
|
||||||
position: 'absolute', top: '10px', right: '10px',
|
|
||||||
background: 'none', border: 'none', color: 'var(--text-mid)',
|
|
||||||
padding: '4px', cursor: 'pointer', lineHeight: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<X size={16} strokeWidth={1.75} />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<div style={{
|
|
||||||
width: '44px', height: '44px', margin: '0 auto 12px',
|
|
||||||
borderRadius: '50%', background: 'var(--gold)',
|
|
||||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
||||||
}}>
|
|
||||||
{mode === 'safari'
|
|
||||||
? <Share size={22} strokeWidth={1.75} color="var(--navy)" />
|
|
||||||
: <ExternalLink size={22} strokeWidth={1.75} color="var(--navy)" />}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{mode === 'safari' ? (
|
|
||||||
<p style={{ fontSize: '14px', color: 'var(--text-dark)', lineHeight: 1.5, margin: 0 }}>
|
|
||||||
To install this app, tap the <strong>Share</strong> icon in Safari's
|
|
||||||
toolbar, then choose <strong>Add to Home Screen</strong>.
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
<p style={{ fontSize: '14px', color: 'var(--text-dark)', lineHeight: 1.5, margin: 0 }}>
|
|
||||||
iOS only allows installing apps from <strong>Safari</strong>. Open this
|
|
||||||
page in Safari, then tap Share → <strong>Add to Home Screen</strong>.
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
import { RefreshCw } from 'lucide-react'
|
|
||||||
|
|
||||||
export function UpdateBanner({ visible }: { visible: boolean }) {
|
|
||||||
if (!visible) return null
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
position: 'fixed',
|
|
||||||
bottom: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
zIndex: 9999,
|
|
||||||
background: 'var(--sidebar)',
|
|
||||||
color: 'var(--text-light)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
gap: '12px',
|
|
||||||
padding: '10px 16px',
|
|
||||||
fontSize: '14px',
|
|
||||||
boxShadow: '0 -2px 8px rgba(0,0,0,0.3)',
|
|
||||||
}}>
|
|
||||||
<span>A new version is available.</span>
|
|
||||||
<button
|
|
||||||
onClick={() => window.location.reload()}
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '6px',
|
|
||||||
background: 'var(--accent)',
|
|
||||||
color: 'var(--sidebar)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '4px',
|
|
||||||
padding: '6px 14px',
|
|
||||||
fontWeight: 600,
|
|
||||||
cursor: 'pointer',
|
|
||||||
fontSize: '13px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<RefreshCw size={14} strokeWidth={1.75} />
|
|
||||||
Reload
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue