Skip to content

feat(search): add an event-filters button beside the map search #38

Closed

Description

@Ardnived

Summary

Add a filter button to the drawer headers of CountriesView and SearchView, sitting beside the geocoder search field and styled identically to the existing close button. Clicking it opens a filter panel (popover) whose settings narrow the events shown in the SearchView list and the event pins/clusters on the map. Today the widget has no way to narrow events by format, schedule, or language — useSearchState.onlineOnly exists but no UI sets it.

Proposed changes

Shared header icon-button atom

  • Extract the iconButton chrome shared by CloseButton / CollapseToggle (src/views/shared.tsx:41-42) into an IconButton atom (src/components/atoms/Button/), so the close, collapse, and new filter buttons render identically side by side. Migrate the two existing callers.
  • Add a FilterIcon (funnel or sliders glyph) to src/components/atoms/Icons/actions.tsx.

Filter button + panel (new component, not part of MapSearch)

  • Keep MapSearch a thin Geocoder wrapper; build a new SearchFilters molecule (src/components/molecules/SearchFilters/) = trigger button + panel, and render it in both headers between SearchField and the close/collapse control (src/views/SearchView/SearchView.tsx:49-52, src/views/CountriesView/CountriesView.tsx:47-50).
  • Panel opens via the shared floating-ui Dropdown atom with role="dialog" + ariaLabel (the pattern from issue refactor(ui): unify dropdowns on a shared floating-ui Dropdown #12; SettingsMenu is the reference). Controls inside use Radix primitives per the issue refactor(ui): migrate components from NextUI to Radix UI #22 direction. If the popover proves cramped on small screens, the implementer may present the same panel content in a modal (@radix-ui/react-dialog, already a dep) below md instead.
  • The trigger shows an active-filter indicator (count badge or dot) when any filter is non-default, and the panel has a "clear all" reset.

Filter options (fields all exist on FeedEvent, src/types/event.ts:82-94):

  • Format — any / in-person / online (eventType). Radix ToggleGroup or Select; replaces the boolean onlineOnly.
  • Time of day — one range with two handles (e.g. 0–24h in 30-min steps) over the event's local start–end time. Needs a new Slider atom wrapping @radix-ui/react-slider (new dep, fits the existing Radix family).
  • Day of week — multi-select of the 7 weekdays (toggle pills; @radix-ui/react-toggle-group or the existing Checkbox). Weekday-name labels via Intl / luxon, honouring the active locale.
  • Language — multi-select checkbox list of the distinct languages codes present in the geojson feed (not hardcoded), labelled via Intl.DisplayNames(locale, { type: 'language' }).
  • Cadence (suggested extra, optional) — weekly class / one-time or monthly event, from schedule.recurrenceType.

State + shared predicate

  • Extend useSearchState (src/config/store.ts:30-43): replace onlineOnly with format, add timeOfDay: [number, number], daysOfWeek: number[], languages: string[] (empty = no restriction), plus setters and a clearFilters action. Read with selectors/useShallow per the store conventions.
  • One pure, unit-tested predicate matchesFilters(event, filters) in src/lib/shape/ shared by the list and the map. Semantics:
    • Day + time are evaluated together per occurrence: an event matches if any schedule.upcomingDates occurrence falls on a selected weekday and starts within the time range (range treated as start-time window; use endTime only if trivially available).
    • Times evaluate in the event's own frame via eventTimeZone (src/lib/shape/event.ts:22-23): the event's zone for in-person, the viewer's zone for online, UTC fallback for null firstDate_tz.
    • When a day/time filter is active, events with no upcomingDates are excluded (can't verify a match); with all filters at defaults every event passes.

Wiring

  • List: DynamicEventsList (src/components/organisms/EventsList/EventsList.tsx:31-49) reads the filter state from the store, includes it in the ['events', …] queryKey, and applies the predicate — replacing the onlineOnly plumbing through getEvents (src/config/api/fetch.ts:278-291).
  • Map: Map.tsx derives a useMemo-filtered FeatureCollection from the cached geojson + the same predicate before feeding the events <Source> (src/components/organisms/Mapbox/Map.tsx:139-151), so cluster counts reflect the filters (a layer-level filter would leave stale cluster counts). Read filters via a useShallow selector — the map is the hot render path.
  • i18n: all new labels from public/locales/<lng>/common.json (en + the other hand-maintained locales), %{var} interpolation.

Non-goals (follow-ups, out of scope)

  • Region/country eventCount badges and RegionView children lists do not react to filters.
  • No URL persistence of filter state (zustand-only, matching useSearchState today); a ?filters= param can be a follow-up.

Acceptance criteria

  • Filter button appears beside the search field in both CountriesView and SearchView headers, visually identical to the close button (both render the shared IconButton atom)
  • Clicking it opens the filter panel; Escape / click-outside dismisses; controls are keyboard-accessible with labels
  • Format, time-of-day (two-handle range), day-of-week, and language filters all narrow the SearchView list
  • Map pins and cluster counts update to the same filtered set as filters change
  • Trigger shows an active-filter indicator when any filter is non-default; "clear all" restores defaults (full list + all pins)
  • Day/time filters evaluate in the event's local timezone (viewer's for online events); events without occurrence data are excluded only while a day/time filter is active
  • Language options are derived from the feed and labelled per the active locale; new UI strings come from locale JSON (en + other locales in sync)
  • Unit tests cover matchesFilters and the extended store; Ladle stories exist for the new atoms + panel
  • Lint + typecheck + test:run + build pass
  • Verified in the running widget (mobile bottom-sheet + desktop panel)

Files affected

  • src/views/shared.tsx — extract IconButton, add filter button to header composition
  • src/components/atoms/Button/ — new IconButton atom; src/components/atoms/Icons/actions.tsx — FilterIcon
  • src/components/atoms/Slider/ — new Radix slider atom (@radix-ui/react-slider dep)
  • src/components/molecules/SearchFilters/ — new filter button + panel
  • src/views/CountriesView/CountriesView.tsx, src/views/SearchView/SearchView.tsx — header wiring
  • src/config/store.ts — extended useSearchState
  • src/lib/shape/ — matchesFilters predicate (+ tests)
  • src/components/organisms/EventsList/EventsList.tsx, src/config/api/fetch.ts — list wiring
  • src/components/organisms/Mapbox/Map.tsx — filtered FeatureCollection
  • public/locales/*/common.json — new filter strings

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions