Files
web-nuxt/app/pages/cool/index.vue
T
Noel Sabia d908c3264d
ci / check (push) Successful in 54s
ci / check (pull_request) Successful in 56s
feat: simplify the Cool City phone decision
- replace the three stacked route cards with a Shortest | Shaded | Accessible segmented control and one large card
- default to Accessible for Ruth; keep the 16:00 trade-off visible as one sentence
- fold the audience vote into the card's primary action so the mobile action stays above the fold
- soften cards with a 28 px radius, soft shadow and one subtle selected ring
- leave the stage and city information architecture intact
2026-11-14 14:15:28 +01:00

420 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 { COOL_ROUTE_IDS, COOL_ROUTE_LABELS, COOL_TIMES, isCoolRound } from '#shared/cool'
import type { CoolDemoState, CoolRouteId, CoolRound, CoolVoteTally } from '#shared/cool'
import { coolMinutes, coolShade } from '~/utils/cool'
const route = useRoute()
const round = ref<CoolRound>(isCoolRound(route.query.round) ? route.query.round : 'preselection')
const voteOnly = computed(() => route.query.vote === '1')
const { bundle } = await useCoolRouteData()
const { data: initialState } = await useFetch<CoolDemoState>('/api/cool/state', {
query: computed(() => ({ round: round.value })),
})
const { data: initialTally } = await useFetch<CoolVoteTally>('/api/cool/vote', {
query: computed(() => ({ round: round.value })),
})
const { state, update } = useCoolDemo(round, initialState.value, initialTally.value)
const { myVote, busy, error: voteError, tally, mounted, vote } = useCoolVote(round)
const timeIndex = computed({
get: () => Math.max(0, COOL_TIMES.indexOf(state.value.time)),
set: (index: number) => {
const time = COOL_TIMES[index] ?? '10:00'
const nextRoute = bundle.value.recommendationByTime[time] ?? state.value.selectedRoute
void update({ time, selectedRoute: nextRoute })
},
})
const timeMarks = COOL_TIMES.map((time, index) => ({ value: index, label: time }))
const modelLabel = computed(() => bundle.value.modelLabel)
const myVoteLabel = computed(() => (myVote.value ? COOL_ROUTE_LABELS[myVote.value] : ''))
const voteStatus = computed(() => {
if (myVote.value) {
return `${myVoteLabel.value} recorded${tally.value ? ` · ${tally.value.total} ${tally.value.total === 1 ? 'vote' : 'votes'} in this room` : ''}.`
}
if (state.value.scene === 'locked' || state.value.scene === 'coda') return 'The vote is closed. The stage has the result.'
return 'The vote opens when the presenter starts it.'
})
const routeReasons: Record<CoolRouteId, string> = {
shortest: 'Fastest, but a 15% ramp at the Marktplatz tram crossing.',
shaded: 'Twice as long, so more minutes in the sun.',
accessible: 'One minute longer, no ramp, water and benches.',
}
const routeOptions = COOL_ROUTE_IDS.map((id) => ({ value: id, label: COOL_ROUTE_LABELS[id] }))
// The phone opens on the model's route. The one pristine state is Shortest at
// 10:00; in that case show Accessible for Ruth. Any explicit stage choice wins.
const localRoute = ref<CoolRouteId>(
state.value.selectedRoute === 'shortest' && state.value.time === '10:00'
? 'accessible'
: state.value.selectedRoute,
)
let lastRemoteRoute = state.value.selectedRoute
const activeRoute = computed<CoolRouteId>({
get: () => localRoute.value,
set: (value) => {
localRoute.value = value
lastRemoteRoute = value
void update({ selectedRoute: value })
},
})
watch(
() => state.value.selectedRoute,
(value) => {
if (value === lastRemoteRoute) return
lastRemoteRoute = value
localRoute.value = value
},
)
const activeRouteOption = computed(
() => bundle.value.routes.find((item) => item.id === activeRoute.value) ?? bundle.value.routes[0],
)
const activeValues = computed(
() => activeRouteOption.value?.values[state.value.time] ?? null,
)
const tradeoff = computed(() => {
const shortest = bundle.value.routes.find((item) => item.id === 'shortest')
const shaded = bundle.value.routes.find((item) => item.id === 'shaded')
const accessible = bundle.value.routes.find((item) => item.id === 'accessible')
if (!shortest || !shaded || !accessible) return ''
const shortestValues = shortest.values[state.value.time]
const shadedValues = shaded.values[state.value.time]
const accessibleValues = accessible.values[state.value.time]
if (!shortestValues || !shadedValues || !accessibleValues) return ''
const shortestRamp = shortest.ramp ? shortest.ramp.incline.replace('.0%', '%') : 'no'
return `Shaded: ${coolShade(shadedValues.shadePct)} shade, but ${coolMinutes(shadedValues.directSunMin)} sun because it is twice as long. Shortest: ${coolMinutes(shortestValues.directSunMin)} sun, ${shortestRamp} ramp. Accessible: ${coolMinutes(accessibleValues.directSunMin)} sun, no ramp.`
})
function tooltipTime(value: number): string {
return COOL_TIMES[value] ?? ''
}
function onSubmit(routeId: CoolRouteId) {
void vote(routeId)
}
watch(
() => route.query.round,
(value) => {
if (isCoolRound(value)) round.value = value
},
)
useHead({
title: voteOnly.value ? 'Vote — Cool City' : 'Cool City — a heat-safe route through Heilbronn',
meta: [
{
name: 'description',
content: voteOnly.value
? 'Which route for Ruth? One anonymous vote for the Cool City demo.'
: 'Cool City is Heilbronn’s public heat-safe route: shortest, shaded and accessible options from Stadtgalerie to Marktplatz, with modelled shade.',
},
{ name: 'theme-color', content: '#f6f3ee' },
],
})
</script>
<template>
<div class="cc-cool">
<header class="cc-topbar">
<NuxtLink to="/cool" class="cc-wordmark">
<span class="cc-mark" aria-hidden="true" />
Cool City
</NuxtLink>
<span class="cc-topbar__place">Heilbronn <span aria-hidden="true">·</span> {{ state.time }}</span>
<span class="cc-topbar__status"><i aria-hidden="true" /> Public route</span>
</header>
<main v-if="voteOnly" class="cc-vote-only">
<div class="cc-vote-only__inner">
<h1>Which route for Ruth?</h1>
<p class="cc-vote-only__lede">Shortest, shaded, or accessible? One tap. No name, no location.</p>
<div v-if="!myVote && state.voteOpen" class="cc-vote-only__buttons">
<OnyxButton
v-for="id in COOL_ROUTE_IDS"
:key="id"
:label="COOL_ROUTE_LABELS[id]"
mode="outline"
:disabled="busy"
@click="onSubmit(id)"
/>
</div>
<div v-else class="cc-vote-only__confirmation" role="status">
<p v-if="myVote">You chose <strong>{{ myVoteLabel }}</strong>.</p>
<p v-else>{{ voteStatus }}</p>
<p class="cc-fine">Aggregate only. One vote per browser and round.</p>
</div>
<p v-if="voteError" class="cc-error" role="alert">{{ voteError }}</p>
<p v-if="!mounted" class="cc-fine">Preparing your anonymous vote…</p>
</div>
</main>
<main v-else class="cc-phone">
<section class="cc-ruth" aria-labelledby="ruth-title">
<h1 id="ruth-title">Ruth, 78, needs to reach Marktplatz.</h1>
<p class="cc-ruth__copy">A hot day in Heilbronn. She needs bread.</p>
<span class="cc-ruth__tag">Composite persona — illustrative, not a real person</span>
</section>
<section class="cc-panel cc-time" aria-labelledby="time-title">
<div class="cc-time__head">
<h2 id="time-title">When?</h2>
<strong>{{ state.time }}</strong>
</div>
<OnyxSlider
v-model="timeIndex"
label="Time of day"
:min="0"
:max="COOL_TIMES.length - 1"
:step="1"
:marks="timeMarks"
:tooltip="{ formatter: tooltipTime }"
/>
<p class="cc-fine">Modeled shade, not measured. The stage follows this time.</p>
</section>
<section class="cc-route" aria-labelledby="route-title">
<div class="cc-route__head">
<h2 id="route-title">Which route for Ruth?</h2>
<p class="cc-route__model">Model recommendation · <strong>{{ modelLabel }}</strong></p>
</div>
<OnyxSegmentedControl
v-model="activeRoute"
class="cc-route__segment"
aria-label="Route"
name="cool-route"
:options="routeOptions"
/>
<CoolRouteCard
v-if="activeRouteOption"
:route="activeRouteOption"
:values="activeValues"
:reason="routeReasons[activeRoute]"
>
<template #action>
<div v-if="myVote" class="cc-route__vote-status" role="status">
<strong>You chose {{ myVoteLabel }}.</strong>
<span>One vote per browser.</span>
</div>
<OnyxButton
v-else-if="state.voteOpen"
:label="`Vote for ${activeRouteOption?.label ?? activeRoute}`"
color="primary"
:disabled="busy"
@click="onSubmit(activeRoute)"
/>
<p v-else class="cc-route__vote-status cc-route__vote-status--quiet">
Voting opens when the presenter starts it.
</p>
<p v-if="voteError" class="cc-error" role="alert">{{ voteError }}</p>
</template>
</CoolRouteCard>
<p v-if="tradeoff" class="cc-route__tradeoff">
<span class="cc-route__tradeoff-label">The trade-off at {{ state.time }}</span>
{{ tradeoff }}
</p>
</section>
<details class="cc-details">
<summary>Details</summary>
<div class="cc-details__body">
<p><strong>Shade is modeled, not measured.</strong> NOAA solar position, building footprints and tree canopies on 14 Aug 2026, a 35°C clear-sky day.</p>
<p><strong>At 16:00:</strong> Shortest 359.5 m / 4.8 min, 43.8% shade, 2.7 min direct sun, 15% ramp. Shaded 732.3 m / 9.8 min, 50.0% shade, 4.9 min direct sun. Accessible 438.2 m / 5.8 min, 43.8% shade, 3.3 min direct sun, no ramp, water 2, benches 6.</p>
<p><strong>All three routes are step-free.</strong> The 15% ramp is at the Marktplatz tram crossing. The city data is a relative index: estimated devices, not people.</p>
<p class="cc-details__links">
<NuxtLink to="/cool/city">How this works</NuxtLink>
<NuxtLink to="/plan">Retail module</NuxtLink>
<NuxtLink to="/cool/stage">Stage</NuxtLink>
</p>
</div>
</details>
<footer class="cc-phone__footer">
<span>Cool City · Heilbronn</span>
<span>Modeled shade, not measured. Estimated devices, not people.</span>
</footer>
</main>
</div>
</template>
<style scoped>
.cc-fine {
margin: 0.35rem 0 0;
color: var(--cc-muted);
font-size: 0.7rem;
line-height: 1.45;
}
.cc-error {
margin: 0.45rem 0 0;
color: var(--cc-heat-text);
font-size: 0.78rem;
}
.cc-vote-only__buttons {
grid-template-columns: minmax(0, 1fr);
}
.cc-vote-only__buttons :deep(.onyx-button) {
width: 100%;
min-height: 52px;
border-radius: 999px;
font-weight: 650;
}
.cc-route {
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.cc-route__head h2 {
margin: 0;
font-size: clamp(1.5rem, 5.2vw, 1.9rem);
font-weight: 850;
letter-spacing: -0.045em;
line-height: 1;
}
.cc-route__model {
margin: 0.3rem 0 0;
color: var(--cc-muted);
font-size: 0.74rem;
line-height: 1.35;
}
.cc-route__model strong {
color: var(--cc-ink);
font-weight: 750;
}
.cc-route__segment {
width: 100%;
}
.cc-route__segment :deep(.onyx-segmented-control) {
display: grid;
max-width: none;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 0.18rem;
padding: 0.22rem;
overflow: visible;
border: 1px solid var(--cc-line);
border-radius: 999px;
background: color-mix(in srgb, var(--cc-ink) 5%, var(--cc-surface-solid));
}
.cc-route__segment :deep(.onyx-segmented-control-element) {
border-radius: 999px;
background: transparent;
color: var(--cc-ink-2);
font-family: var(--cc-font);
font-weight: 650;
}
.cc-route__segment :deep(.onyx-segmented-control-element__label) {
min-width: 0;
min-height: 42px;
align-items: center;
padding: 0.3rem 0.35rem;
font-size: 0.8rem;
font-weight: inherit;
}
.cc-route__segment :deep(.onyx-segmented-control-element:hover) {
color: var(--cc-ink);
background: color-mix(in srgb, var(--cc-ink) 4%, transparent);
}
.cc-route__segment :deep(.onyx-segmented-control-element:has(.onyx-segmented-control-element__input:checked)) {
background: var(--cc-ink);
color: var(--cc-ground);
}
.cc-route__segment :deep(.onyx-segmented-control-element:has(.onyx-segmented-control-element__input:checked):hover) {
background: var(--cc-ink);
color: var(--cc-ground);
}
.cc-route__segment :deep(.onyx-segmented-control-element:has(.onyx-segmented-control-element__input:focus-visible)) {
outline: 2px solid var(--cc-focus);
outline-offset: 2px;
}
.cc-route__vote-status {
display: flex;
min-height: 48px;
flex-wrap: wrap;
align-content: center;
align-items: baseline;
gap: 0.3rem 0.55rem;
color: var(--cc-muted);
font-size: 0.84rem;
line-height: 1.4;
}
.cc-route__vote-status strong {
color: var(--cc-ink);
font-weight: 750;
}
.cc-route__vote-status--quiet {
display: block;
padding-block: 0.65rem;
}
.cc-route__tradeoff {
max-width: 62ch;
margin: 0;
color: var(--cc-muted);
font-size: 0.78rem;
line-height: 1.5;
}
.cc-route__tradeoff-label {
display: block;
margin-bottom: 0.15rem;
color: var(--cc-ink);
font-size: 0.64rem;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
@media (min-width: 900px) {
.cc-route {
gap: 0.9rem;
}
.cc-route__head h2 {
font-size: 2rem;
}
.cc-route__segment {
max-width: 30rem;
}
.cc-route__tradeoff {
font-size: 0.8rem;
}
}
@media (max-width: 420px) {
.cc-route__vote-status {
display: block;
min-height: 0;
padding-block: 0.25rem;
}
}
</style>