import { RotateCw, AlertTriangle } from 'lucide-react' import { useTranslation } from '../../i18n' import { Tooltip } from '../shared/Tooltip' import type { ExplorePoiCategory, PoiCategoryGroups } from './usePoiCategories' interface Props { /** The chips to offer, from usePoiCategories by way of usePoiExplore. */ categories: PoiCategoryGroups active: Set onToggle: (key: string) => void loadingKeys?: Set /** categories whose last fetch failed → show a retry affordance */ errorKeys?: Set /** true when the map moved since the last search → offer "search this area" */ moved?: boolean onSearchArea?: () => void /** Stretch the bar across its container and spread the segments evenly. * The phone map gives it the full width between the screen margins; on * desktop it floats, so it stays content-width there. */ fullWidth?: boolean /** The phone shell's chrome: the glass, hairline and 36px height of the day rail * and the tab switch above it, so the three bars read as one set. */ phoneChrome?: boolean } // The touch target every segment keeps, however many categories there are. const SEGMENT = 34 // On the phone the segment is as tall as a day chip; it keeps its width. const PHONE_SEGMENT_HEIGHT = 28 /** The phone shell's glass, as the day rail draws it (bg/border --m-glass/--m-gbr). */ const PHONE_GLASS: React.CSSProperties = { background: 'var(--m-glass)', border: '1px solid var(--m-gbr)', backdropFilter: 'blur(24px) saturate(170%)', WebkitBackdropFilter: 'blur(24px) saturate(170%)', } // How far one wheel step moves the bar. Firefox counts a mouse wheel in lines and // some drivers in pages; a line moves about one segment, a page one bar width. function wheelPixels(e: React.WheelEvent, barWidth: number): number { if (e.deltaMode === WheelEvent.DOM_DELTA_LINE) return e.deltaY * SEGMENT if (e.deltaMode === WheelEvent.DOM_DELTA_PAGE) return e.deltaY * barWidth return e.deltaY } // The bar only ever overflows sideways and a plain mouse wheel only turns vertically, // so on desktop the chips past the corridor edge (the plugin ones first) were out of // reach without a trackpad. While the bar overflows, a mostly vertical turn scrolls it // sideways. A sideways swipe or Shift+wheel already scrolls it natively and is left alone. // In a right-to-left language the chips overflow to the left and scrollLeft runs from 0 // down into negative numbers, so the same turn has to count the other way to reach them. function wheelSideways(e: React.WheelEvent) { const bar = e.currentTarget if (bar.scrollWidth <= bar.clientWidth || Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return const towardEnd = getComputedStyle(bar).direction === 'rtl' ? -1 : 1 bar.scrollLeft += towardEnd * wheelPixels(e, bar.clientWidth) } interface SegmentProps { cat: ExplorePoiCategory on: boolean loading: boolean failed: boolean fullWidth?: boolean phoneChrome?: boolean onToggle: (key: string) => void } function Segment({ cat, on, loading, failed, fullWidth, phoneChrome, onToggle }: Readonly) { return ( ) } // Frosted, icon-only segmented control that floats over the map. Active segments // fill with the category colour (matching their markers); the label shows in a // custom tooltip on hover so the pill stays compact. The core categories come first // and whatever plugins add follows a thin divider (#1781); once that is more than the // width holds, the bar scrolls sideways (by swipe, trackpad or mouse wheel) rather than // shrinking a segment below the touch target. export default function PoiCategoryPill({ categories, active, onToggle, loadingKeys, errorKeys, moved, onSearchArea, fullWidth, phoneChrome }: Readonly) { const { t } = useTranslation() const anyError = !!errorKeys && Array.from(active).some(k => errorKeys.has(k)) const frosted: React.CSSProperties = phoneChrome ? PHONE_GLASS : { background: 'var(--sidebar-bg)', backdropFilter: 'blur(20px) saturate(180%)', WebkitBackdropFilter: 'blur(20px) saturate(180%)', boxShadow: 'var(--sidebar-shadow, 0 4px 16px rgba(0,0,0,0.14))', } const segment = (cat: ExplorePoiCategory) => { const on = active.has(cat.key) // Only an active category can be loading: a deselected one whose fetch // is still winding down must not keep spinning. const loading = on && !!loadingKeys?.has(cat.key) return ( ) } return (
{categories.core.map(segment)} {categories.plugin.length > 0 && (
)} {categories.plugin.map(segment)}
{(moved || anyError) && active.size > 0 && ( )}
) }