Files
web-nuxt/app/pages/live.vue
T
Noel Sabia 836e71c5f4 feat(web): replace UI with greenfield Stitch sensing-engine hero
Rebuild the web frontend around the Stitch hero design: new app shell header with responsive navigation and a single / page preserving the Stitch main/footer copy. Remove the legacy Onyx pages, components, composables and CSS. Add bundled Tailwind 3.4.17 and @nuxt/icon with a locally bundled Material Symbols collection; no icon CDN at runtime. Include design notes for claims to reconcile before the pitch and verification screenshots.
2026-11-14 17:06:35 +01:00

507 lines
13 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { iconSync, iconTriangleWarning } from '@sit-onyx/icons'
import { addDays, berlinParts, planWeekStart } from '#shared/staffing'
import { scenarioLabel } from '#shared/live'
import type { ScenarioState, Sensor, StaffingResponse } from '#shared/types'
import {
formatDateTime,
formatEuro,
formatNumber,
formatPercent,
formatShortDate,
formatTime,
formatWeekday,
weekLabel,
} from '~/utils/format'
import {
peakHourOf,
peakShiftOf,
planDays,
savingOf,
totalStaffHoursOf,
} from '~/utils/plan'
const config = useRuntimeConfig()
const demoNow = String(config.public.demoNow)
const { data: sensors } = await useFetch<Sensor[]>('/api/sensors')
const { data: initialScenario } = await useFetch<ScenarioState>('/api/scenario')
const sensorId = ref(
sensors.value?.find((sensor) => sensor.id === 'hn-stadtgalerie-01')?.id ??
sensors.value?.[0]?.id ??
'hn-stadtgalerie-01',
)
const live = useLiveScenario(initialScenario.value)
const {
data: planData,
error: planError,
refresh: refreshPlan,
} = await useFetch<StaffingResponse>('/api/staffing', {
query: computed(() => ({
sensor: sensorId.value,
scenario: live.scenarioId,
standard: 'standard',
})),
})
let lastScenarioId = live.scenarioId
watch(
() => live.revision,
() => {
if (live.scenarioId === lastScenarioId) void refreshPlan()
lastScenarioId = live.scenarioId
},
)
const plan = computed(() => planData.value ?? null)
const activeSensor = computed(() => sensors.value?.find((sensor) => sensor.id === sensorId.value))
const peakShift = computed(() => peakShiftOf(plan.value))
const peakHour = computed(() => peakHourOf(plan.value))
const totalStaffHours = computed(() => totalStaffHoursOf(plan.value))
const savingEur = computed(() => savingOf(plan.value))
const savingPct = computed(() => savingPctOf(plan.value))
const daySummaries = computed(() => planDays(plan.value))
const weekStart = computed(() => {
const first = plan.value?.hours[0]
return first ? berlinParts(first.t).date : planWeekStart(demoNow)
})
const weekEnd = computed(() => addDays(weekStart.value, 6))
const today = computed(() => berlinParts(demoNow).date)
const windowTag = computed(() => {
if (!plan.value) return 'No plan'
return weekStart.value <= today.value && today.value <= weekEnd.value ? 'Today–Friday' : 'Seven days'
})
const windowLabel = computed(() => (plan.value ? weekLabel(weekStart.value, weekEnd.value) : 'Window unavailable'))
const freshness = computed(() => live.lastEventAt || live.scenarioAt || plan.value?.context_version || '')
const scenarioName = computed(() => scenarioLabel(live.scenarioId))
const reason = computed(() => {
if (peakHour.value) {
return `Peak forecast ${formatNumber(peakHour.value.footfall)} est. devices/hour at ${formatTime(peakHour.value.t)}.`
}
return plan.value?.why[0] ?? 'Waiting for the forecast.'
})
const changed = ref(false)
let changedTimer: ReturnType<typeof setTimeout> | undefined
let mounted = false
watch(
() => live.revision,
() => {
if (!mounted) return
changed.value = true
if (changedTimer) clearTimeout(changedTimer)
changedTimer = setTimeout(() => {
changed.value = false
}, 8000)
},
)
onMounted(() => {
mounted = true
})
onBeforeUnmount(() => {
if (changedTimer) clearTimeout(changedTimer)
})
useHead({
title: 'Live plan — PulseCast',
meta: [{ name: 'theme-color', content: '#0e100e' }],
})
</script>
<template>
<div class="pc-dark live">
<header class="live__top">
<NuxtLink to="/" class="live__wordmark">
<span class="live__mark" aria-hidden="true" />
PulseCast
</NuxtLink>
<span class="live__top-status">
<LiveStatusBadge :status="live.status" :last-event-at="live.lastEventAt" dark />
</span>
</header>
<main class="live__main">
<div v-if="planError" class="pc-alert pc-alert--dark live__alert" role="alert">
<OnyxIcon :icon="iconTriangleWarning" size="18px" color="warning" />
<span>The live plan is unavailable. Retry, or keep the last known plan on screen.</span>
<OnyxButton label="Retry" mode="outline" density="compact" :icon="iconSync" @click="refreshPlan()" />
</div>
<section class="live__hero" aria-labelledby="live-title">
<div class="live__hero-top">
<span class="pc-tag pc-tag--dark">{{ windowTag }}</span>
<span v-if="changed" class="pc-tag pc-tag--signal" role="status">Plan updated</span>
</div>
<p class="live__day">
<template v-if="peakShift">
{{ formatWeekday(peakShift.date) }} {{ formatShortDate(peakShift.date) }} · peak shift
</template>
<template v-else>Waiting for the plan</template>
</p>
<h1 id="live-title" class="live__number">
<template v-if="peakShift">{{ peakShift.staff }}<span class="live__unit">staff</span></template>
<template v-else><span class="live__number-empty">No plan</span></template>
</h1>
<p class="live__shift">
<template v-if="peakShift">{{ peakShift.start }}–{{ peakShift.end }}</template>
<template v-else>The next shift appears here.</template>
</p>
<p class="live__reason">{{ reason }}</p>
<p class="live__fresh">
<span>{{ freshness ? `Updated ${formatDateTime(freshness)}` : 'Waiting for the live stream' }}</span>
<span>v{{ live.version || '—' }}</span>
</p>
</section>
<section class="live__board" aria-labelledby="live-week-title">
<div class="live__section-head">
<h2 id="live-week-title" class="pc-label">The week</h2>
<span>{{ windowLabel }} · {{ windowTag }}</span>
</div>
<WeekBoard
v-if="daySummaries.length"
:days="daySummaries"
:peak-date="peakShift?.date"
dense
dark
label="The week at a glance"
/>
<div v-else class="pc-skeleton pc-skeleton--dark" style="height: 7rem" aria-busy="true" />
</section>
<section class="live__receipt" aria-label="Plan cost and coverage">
<div>
<span class="pc-label">Staff-hours</span>
<strong>{{ plan ? totalStaffHours : '—' }}</strong>
</div>
<div>
<span class="pc-label">Planned cost</span>
<strong>{{ plan ? formatEuro(plan.summary.cost_eur) : '—' }}</strong>
<small v-if="plan">vs {{ formatEuro(plan.summary.flat_schedule_cost_eur) }} flat · {{ formatEuro(savingEur) }} saved</small>
<small v-else>Waiting for the plan</small>
</div>
<div>
<span class="pc-label">Coverage</span>
<strong>{{ plan ? formatPercent(plan.summary.coverage_pct, 1) : '—' }}</strong>
<small v-if="plan">{{ plan.summary.understaffed_hours }} h short · {{ plan.summary.overstaffed_hours }} h over</small>
<small v-else>Waiting for the plan</small>
</div>
</section>
<section class="live__context" aria-label="Live context">
<div><span>Scenario</span><strong>{{ scenarioName }}</strong></div>
<div>
<span>Transport</span>
<strong>{{ live.statusLabel }}<template v-if="live.status === 'polling'"> · 5 s</template></strong>
</div>
<div><span>Updated</span><strong>{{ freshness ? formatDateTime(freshness) : '—' }}</strong></div>
</section>
<NuxtLink class="pc-link-button pc-link-button--primary live__cta" to="/plan">
Open the full plan <span aria-hidden="true">→</span>
</NuxtLink>
<p class="live__note">
Estimated devices, not people. {{ plan?.assumptions.visitors_per_staff_hour ?? 25 }} visitors/staff-hour ·
×{{ plan?.assumptions.safety_factor ?? 1.15 }} safety · €{{ plan?.assumptions.labor_cost_eur_h ?? 16 }}/h.
No login. If the stream drops, this page polls every five seconds.
</p>
<p v-if="activeSensor" class="live__sensor">{{ activeSensor.name }} · {{ activeSensor.id }}</p>
</main>
</div>
</template>
<style scoped>
.live {
min-height: 100dvh;
padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
max(1.25rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.live__top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.75rem;
width: 100%;
max-width: 34rem;
margin-inline: auto;
padding-bottom: 0.7rem;
border-bottom: 1px solid var(--pc-dark-line);
}
.live__wordmark {
display: inline-flex;
align-items: center;
gap: 0.45rem;
color: var(--pc-paper);
font-size: 0.82rem;
font-weight: 800;
letter-spacing: -0.02em;
text-decoration: none;
}
.live__mark {
display: block;
width: 0.42rem;
height: 1.1rem;
background: var(--pc-signal-bright);
}
.live__top-status {
display: inline-flex;
align-items: center;
}
.live__main {
display: flex;
width: 100%;
max-width: 34rem;
flex-direction: column;
gap: 0.9rem;
margin-inline: auto;
padding-top: 0.85rem;
}
.live__alert {
margin-top: 0.25rem;
}
.live__hero {
display: flex;
flex-direction: column;
gap: 0.25rem;
padding-bottom: 0.9rem;
border-bottom: 2px solid var(--pc-paper);
}
.live__hero-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
margin-bottom: 0.5rem;
}
.live__hero .pc-label {
color: var(--pc-dark-muted);
}
.live__day {
margin: 0;
color: var(--pc-dark-muted);
font-size: 0.8rem;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.live__number {
display: flex;
align-items: baseline;
gap: 0.45rem;
margin: 0;
color: var(--pc-signal-bright);
font-size: clamp(7.5rem, 38vw, 12rem);
font-stretch: 74%;
font-weight: 850;
line-height: 0.78;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.live__unit {
color: var(--pc-paper);
font-size: clamp(1rem, 4.2vw, 1.35rem);
font-stretch: 100%;
font-weight: 700;
letter-spacing: 0;
text-transform: uppercase;
}
.live__number-empty {
color: var(--pc-paper);
font-size: clamp(2rem, 9vw, 3rem);
font-stretch: 100%;
letter-spacing: -0.02em;
}
.live__shift {
margin: 0.5rem 0 0;
color: var(--pc-paper);
font-size: clamp(1.8rem, 8.5vw, 2.6rem);
font-weight: 800;
letter-spacing: -0.03em;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.live__reason {
max-width: 34ch;
margin: 0.6rem 0 0;
color: var(--pc-dark-muted);
font-size: 0.86rem;
line-height: 1.4;
}
.live__fresh {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 0.4rem;
margin: 0.8rem 0 0;
color: var(--pc-dark-muted);
font-size: 0.7rem;
font-variant-numeric: tabular-nums;
letter-spacing: 0.02em;
}
.live__fresh span:last-child {
color: var(--pc-paper);
font-weight: 700;
}
.live__board {
display: flex;
flex-direction: column;
gap: 0.4rem;
}
.live__section-head {
display: flex;
flex-wrap: wrap;
align-items: baseline;
justify-content: space-between;
gap: 0.35rem;
color: var(--pc-dark-muted);
font-size: 0.68rem;
font-variant-numeric: tabular-nums;
}
.live__section-head .pc-label {
color: var(--pc-dark-muted);
}
.live__receipt {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
border-block: 1px solid var(--pc-dark-line);
}
.live__receipt > div {
min-width: 0;
padding: 0.55rem 0.5rem;
border-inline-end: 1px solid var(--pc-dark-line);
}
.live__receipt > div:first-child {
padding-inline-start: 0;
}
.live__receipt > div:last-child {
border-inline-end: 0;
padding-inline-end: 0;
}
.live__receipt .pc-label {
display: block;
color: var(--pc-dark-muted);
font-size: 0.58rem;
}
.live__receipt strong {
display: block;
margin-top: 0.25rem;
color: var(--pc-paper);
font-size: clamp(1.15rem, 5vw, 1.5rem);
font-weight: 800;
letter-spacing: -0.02em;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.live__receipt small {
display: block;
margin-top: 0.25rem;
color: var(--pc-dark-muted);
font-size: 0.58rem;
line-height: 1.3;
}
.live__context {
display: grid;
gap: 0.15rem;
padding-block: 0.55rem;
border-bottom: 1px solid var(--pc-dark-line);
}
.live__context > div {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 0.75rem;
padding-block: 0.22rem;
}
.live__context span {
color: var(--pc-dark-muted);
font-size: 0.68rem;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.live__context strong {
color: var(--pc-paper);
font-size: 0.76rem;
font-weight: 650;
text-align: right;
}
.live__cta {
width: 100%;
}
.live__note {
margin: 0;
color: var(--pc-dark-muted);
font-size: 0.68rem;
line-height: 1.5;
}
.live__sensor {
margin: 0;
color: var(--pc-dark-muted);
font-family: var(--pc-font);
font-size: 0.6rem;
letter-spacing: 0.03em;
opacity: 0.75;
}
@media (min-width: 700px) {
.live {
padding-block: 2rem;
}
.live__top,
.live__main {
max-width: 36rem;
}
.live__main {
gap: 1.1rem;
}
}
</style>