From 44bc6207a9492089fa87fd2a12c02e5d09d0483e Mon Sep 17 00:00:00 2001 From: HangerThem Date: Sat, 7 Nov 2026 12:01:08 +0100 Subject: [PATCH] feat(ui): polish pass - visual refresh, dark mode, smoother map, mobile sheet Visual - Design tokens (spacing, radius, type, motion) with a dark theme that follows prefers-color-scheme; map palette in theme.ts (exports/print stay light) - Segmented controls (language, colour scheme), switches, styled slider/select, icon buttons, cards, focus rings, hover/active states, reduced-motion support - Info panel card with animation, tooltip that stays on screen, grouped zoom buttons Map - Redraws batched per animation frame; animated zoom/fit, pan inertia, trackpad pinch, pointer cursor and outline for the hovered building - Hovering a legend row highlights that category on the map Loading & feedback - Progress bar + "Loading n/m" pill; status line with icons, collapsible basemap failure details, success messages fade - A newer load supersedes one in flight; a failed buildings query is reported immediately instead of after the basemap retries Convenience - Keyboard: +/- zoom, 0 fit, arrows pan, Esc closes - Legend All/None, double-click or Alt-click to show only one category - Settings and last location remembered; #lat,lon,radius in the URL to share, copy-link button, "my location" button - Mobile: full-screen map with a draggable bottom sheet Co-Authored-By: Claude Opus 5.5 --- src/actions.ts | 108 ++- src/basemap.ts | 35 +- src/components/App.tsx | 10 + src/components/InfoPanel.tsx | 36 +- src/components/Legend.tsx | 50 +- src/components/LoadingOverlay.tsx | 25 + src/components/MapView.tsx | 88 ++- src/components/Sidebar.tsx | 396 +++++++---- src/components/StatusLine.tsx | 49 ++ src/components/ui/Icon.tsx | 95 +++ src/components/ui/Segmented.tsx | 61 ++ src/components/ui/Switch.tsx | 25 + src/export.ts | 7 +- src/fetch.ts | 30 +- src/i18n.ts | 77 ++- src/interaction.ts | 198 +++++- src/main.tsx | 30 +- src/persist.ts | 51 ++ src/render.ts | 155 ++++- src/state.ts | 54 +- src/style.css | 1069 ++++++++++++++++++++++++----- src/theme.ts | 105 +++ 22 files changed, 2270 insertions(+), 484 deletions(-) create mode 100644 src/components/LoadingOverlay.tsx create mode 100644 src/components/StatusLine.tsx create mode 100644 src/components/ui/Icon.tsx create mode 100644 src/components/ui/Segmented.tsx create mode 100644 src/components/ui/Switch.tsx create mode 100644 src/persist.ts create mode 100644 src/theme.ts diff --git a/src/actions.ts b/src/actions.ts index 6821353..5121f40 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -2,13 +2,36 @@ import { batch } from '@preact/signals' import { fetchArea } from './fetch' import { D2R } from './geo' import { t } from './i18n' +import { writeHash } from './persist' import { fitView } from './render' -import { base, busy, hidden, radius, rawBuildings, S, sel, status, type Status } from './state' +import { + base, + busy, + hidden, + lastLoc, + locating, + locText, + progress, + radius, + rawBuildings, + S, + sel, + status, + toast, + type Status, +} from './state' import type { AreaData, LatLon } from './types' import { errMsg } from './util' -export function setStatus(fn: () => string, cls?: Status['cls']) { - status.value = { fn, cls } +export function setStatus(fn: () => string, cls?: Status['cls'], details?: string[]) { + status.value = { fn, cls, details } +} + +let toastTimer: ReturnType | undefined +export function showToast(fn: () => string) { + clearTimeout(toastTimer) + toast.value = { fn, id: Date.now() } + toastTimer = setTimeout(() => (toast.value = null), 2400) } export function applyData(d: AreaData, lon: number, lat: number) { @@ -25,33 +48,88 @@ export function applyData(d: AreaData, lon: number, lat: number) { }) } +let loadSeq = 0 +/** Load an area from ČÚZK. A newer call supersedes one still in flight. */ export async function liveLoad(p: LatLon, quietFallback: boolean): Promise { - busy.value = true - setStatus(() => t('st_loading')) + const my = ++loadSeq + const current = () => my === loadSeq + batch(() => { + busy.value = true + progress.value = { done: 0, total: 0 } + setStatus(() => t('st_loading')) + }) try { - const d = await fetchArea(p.lon, p.lat, radius.value, (n, m) => - setStatus(() => t('st_progress', n, m)), - ) + const r = radius.value + const d = await fetchArea(p.lon, p.lat, r, (done, total) => { + if (current()) progress.value = { done, total } + }) + if (!current()) return false if (!d.buildings.length) { setStatus(() => t('st_none'), 'err') return false } applyData(d, p.lon, p.lat) + writeHash(p, r) + lastLoc.value = { lat: p.lat, lon: p.lon } const loc = `${p.lat.toFixed(5)}, ${p.lon.toFixed(5)}`, n = d.buildings.length, fails = d.fails - setStatus( - () => - t('st_loaded', loc, n) + - (fails.length ? '\n' + t('st_baseFail', fails.length) + '\n' + fails.join('\n') : ''), - fails.length ? 'err' : 'ok', - ) + if (fails.length) + setStatus(() => t('st_loaded', loc, n) + ' ' + t('st_baseFail', fails.length), 'warn', fails) + else setStatus(() => t('st_loaded', loc, n), 'ok') return true } catch (e) { + if (!current()) return false const msg = errMsg(e) setStatus(() => (quietFallback ? t('st_fallback', msg) : t('st_err', msg)), 'err') return false } finally { - busy.value = false + if (current()) + batch(() => { + busy.value = false + progress.value = null + }) + } +} + +const inCzechia = (p: LatLon) => p.lat >= 48 && p.lat <= 52 && p.lon >= 12 && p.lon <= 19 + +/** Load the area around the device's position. */ +export function locate() { + if (!('geolocation' in navigator)) { + setStatus(() => t('geo_unavailable'), 'err') + return + } + locating.value = true + setStatus(() => t('locating')) + navigator.geolocation.getCurrentPosition( + (pos) => { + locating.value = false + const p = { lat: pos.coords.latitude, lon: pos.coords.longitude } + if (!inCzechia(p)) { + setStatus(() => t('geo_outside'), 'err') + return + } + locText.value = `${p.lat.toFixed(6)}, ${p.lon.toFixed(6)}` + liveLoad(p, false) + }, + (err) => { + locating.value = false + setStatus( + () => t(err.code === err.PERMISSION_DENIED ? 'geo_denied' : 'geo_unavailable'), + 'err', + ) + }, + { enableHighAccuracy: true, timeout: 15000, maximumAge: 60000 }, + ) +} + +export async function copyLink() { + try { + await navigator.clipboard.writeText(location.href) + showToast(() => t('linkCopied')) + } catch { + // clipboard blocked (e.g. insecure context): let the user copy it manually + window.prompt(t('copyLink'), location.href) } } diff --git a/src/basemap.ts b/src/basemap.ts index 04a0030..40698ac 100644 --- a/src/basemap.ts +++ b/src/basemap.ts @@ -1,3 +1,5 @@ +import type { BaseColor } from './theme' + /* ================= basemap styles ================= */ /** ZABAGED layer ids on the ČÚZK MapServer. */ export const ZAB_LAYERS = { @@ -15,17 +17,18 @@ export const ZAB_LAYERS = { } export type BaseKey = keyof typeof ZAB_LAYERS +/** Colours are palette keys (theme.ts), so the basemap follows light/dark mode. */ interface PolyStyle { k: BaseKey t: 'poly' - fill: string - stroke?: string + fill: BaseColor + stroke?: BaseColor } /** m: width in true metres, min: minimum width in px */ interface LineStyle { k: BaseKey t: 'line' - c: string + c: BaseColor m: number min: number dash?: number[] @@ -34,17 +37,17 @@ export type BaseStyle = PolyStyle | LineStyle // Drawn in this order (later entries on top) export const BASE: BaseStyle[] = [ - { k: 'garden', t: 'poly', fill: '#e6efd6' }, - { k: 'green', t: 'poly', fill: '#cfe4bd' }, - { k: 'cemetery', t: 'poly', fill: '#c9d9bd', stroke: '#9bb08a' }, - { k: 'parking', t: 'poly', fill: '#e2e2e2', stroke: '#c4c4c4' }, - { k: 'water', t: 'poly', fill: '#a8cfe8', stroke: '#7fb2d6' }, - { k: 'stream', t: 'line', c: '#7fb2d6', m: 2, min: 1.2 }, - { k: 'path', t: 'line', c: '#b58b5a', m: 1, min: 0.8, dash: [2, 3] }, - { k: 'track', t: 'line', c: '#c9a16b', m: 2, min: 1, dash: [6, 4] }, - { k: 'rail', t: 'line', c: '#666666', m: 3, min: 1.2, dash: [8, 4] }, - { k: 'street', t: 'line', c: '#9a9a9a', m: 7, min: 2.4 }, - { k: 'street', t: 'line', c: '#ffffff', m: 5, min: 1.8 }, - { k: 'road', t: 'line', c: '#b8862f', m: 11, min: 3.6 }, - { k: 'road', t: 'line', c: '#ffe08a', m: 8.5, min: 2.8 }, + { k: 'garden', t: 'poly', fill: 'garden' }, + { k: 'green', t: 'poly', fill: 'green' }, + { k: 'cemetery', t: 'poly', fill: 'cemetery', stroke: 'cemeteryEdge' }, + { k: 'parking', t: 'poly', fill: 'parking', stroke: 'parkingEdge' }, + { k: 'water', t: 'poly', fill: 'water', stroke: 'waterEdge' }, + { k: 'stream', t: 'line', c: 'stream', m: 2, min: 1.2 }, + { k: 'path', t: 'line', c: 'path', m: 1, min: 0.8, dash: [2, 3] }, + { k: 'track', t: 'line', c: 'track', m: 2, min: 1, dash: [6, 4] }, + { k: 'rail', t: 'line', c: 'rail', m: 3, min: 1.2, dash: [8, 4] }, + { k: 'street', t: 'line', c: 'streetCasing', m: 7, min: 2.4 }, + { k: 'street', t: 'line', c: 'street', m: 5, min: 1.8 }, + { k: 'road', t: 'line', c: 'roadCasing', m: 11, min: 3.6 }, + { k: 'road', t: 'line', c: 'road', m: 8.5, min: 2.8 }, ] diff --git a/src/components/App.tsx b/src/components/App.tsx index a147916..b363f0d 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1,5 +1,8 @@ import { useSignalEffect } from '@preact/signals' +import { useEffect } from 'preact/hooks' import { lang, t } from '../i18n' +import { attachKeyboard } from '../interaction' +import { toast } from '../state' import { MapView } from './MapView' import { Sidebar } from './Sidebar' @@ -8,10 +11,17 @@ export function App() { document.documentElement.lang = lang.value document.title = t('title') + ' – RÚIAN' }) + useEffect(attachKeyboard, []) + const tst = toast.value return (
+ {tst && ( +
+ {tst.fn()} +
+ )}
) } diff --git a/src/components/InfoPanel.tsx b/src/components/InfoPanel.tsx index dae03d3..c232e2a 100644 --- a/src/components/InfoPanel.tsx +++ b/src/components/InfoPanel.tsx @@ -1,7 +1,8 @@ -import { catLabel, catOf } from '../categories' +import { catColor, catLabel, catOf } from '../categories' import { m2ll } from '../geo' import { ruianUseName, t } from '../i18n' import { sel } from '../state' +import { Icon } from './ui/Icon' const DASH = '—' const orDash = (v: number | null, unit = '') => (v == null ? DASH : v + unit) @@ -10,19 +11,32 @@ const orDash = (v: number | null, unit = '') => (v == null ? DASH : v + unit) export function InfoPanel() { const b = sel.value if (!b) return null - const ll = m2ll((b.bb[0] + b.bb[2]) / 2, (b.bb[1] + b.bb[3]) / 2) + const cat = catOf(b), + ll = m2ll((b.bb[0] + b.bb[2]) / 2, (b.bb[1] + b.bb[3]) / 2) + const title = b.cp ? t('hn', b.cp) : t('nohn') return ( -
- (sel.value = null)}> - ✕ - - {b.cp ? t('hn', b.cp) : t('nohn')} + // key: replay the entry animation when another building is selected +