Skip to content

feat(search): filter events by a date range - #50

Merged
Ardnived merged 6 commits into
mainfrom
feat/date-range-filter
Jul 14, 2026
Merged

Ardnived merged 6 commits into
mainfrom
feat/date-range-filter

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

  • Adds a date-range filter to the /filters drawer: pick a start and/or end date within the next 12 months and keep only events with an upcoming occurrence in that window. Like every other filter it lives in the URL (dates=…), so a dated view is linkable/shareable, and it drives the map, results list, active-filter pills, and the FilterButton badge through the single matchesFilters predicate.
  • Bounded and self-guarding: the picker is capped to [today, today + 12 months], and an out-of-window / reversed / malformed value — whether hand-crafted in the URL or keyboard-typed into the input — is clamped or dropped, never trusted.
  • Localized across all 10 locales (filters.dates.*).

Changes

  • src/lib/shape/filters.ts — dateRange group on EventFilters / DEFAULT_FILTERS (frozen), isDateRestricted, a shared dateWindow(), the per-occurrence date check inside matchesFilters (evaluated in the event's own timezone, together with day + time), the counts + filtersKey, and the dates URL codec (parseDates with the window clamp).
  • src/hooks/use-filters.ts — setDateRange.
  • src/components/molecules/SearchFilters/SearchFilters.tsx — a Date FilterGroup with two native <input type="date"> (module-private DateBound), bounded and kept pair-valid.
  • src/components/molecules/ActiveFilterPills/ActiveFilterPills.tsx — one collapsed, removable date pill.
  • public/locales/*/common.json — filters.dates.* in all 10 locales.

Verification

  • Lint: ✓ (pnpm lint)
  • Types: ✓ (pnpm typecheck)
  • Tests: ✓ Unit lane green — 175 tests (pnpm test:run), incl. new predicate coverage (range in/out, per-occurrence AND with day/time, timezone frames online/null-tz, empty-dates exclusion) and codec coverage (round-trip, open bounds, window clamp, reversed, malformed/non-canonical).
  • Build: ✓ (pnpm build) and Ladle (pnpm ladle:build)

Manual / visual verification

Verified in the running widget against the seeded backend:

  1. /filters → Date group renders with From/To native inputs bounded to today … today + 12 months.
  2. Setting Jul 20–27 updates the live count ("Apply (468)"); applying writes ?dates=2026-07-20,2026-07-27 and filters the list to events with an in-window occurrence — confirmed by per-occurrence semantics (e.g. a weekly Thursday event, next shown "Starting Jul 16", matches via its Jul 23 occurrence).
  3. The active range shows as one removable pill ("Jul 20, 2026 – Jul 27, 2026"); its X clears it (URL drops dates=) and the FilterButton badge counts it ("Filters (1)").
  4. French locale (?locale=fr): heading "Date", inputs "Du" / "Au", pill "20 juil. 2026 – 27 juil. 2026" — localized, no raw keys.

Notes for reviewer

  • Occurrence dates are compared as yyyy-MM-dd strings in the event's own frame (eventTimeZone: viewer zone for online, firstDate_tz otherwise, UTC for null-tz) — the same rule the existing day/time filters use; the filter bounds are viewer-local calendar dates. This is intentional and consistent with the other per-occurrence filters.
  • The /simplify pass extracted the DateBound helper and dropped a redundant tuple in filtersKey; the /code-review pass added the keyboard-entry clamp (native date inputs enforce min/max only in the calendar UI, not for typed values). Two review nits were dismissed with reasons: the mixed-tz-frame is by design (matches the day/time filters), and the pill's DATE_MED (which includes the year) is the format the issue specifies and disambiguates year-spanning ranges.
  • src/views/FilterView/FilterView.tsx needed no change (it already renders <SearchFilters> + the Apply count).

Closes #48

🤖 Generated with Claude Code

Ardnived and others added 5 commits July 14, 2026 16:07
Add a `dateRange` group to `EventFilters` — a start/end pair of optional
`yyyy-MM-dd` calendar dates (both null = no restriction). `matchesFilters`
applies it inside the per-occurrence `upcomingDates` loop, so one occurrence
must satisfy weekday, time-of-day, and date-range together, read in the
event's own frame via `eventTimeZone`. The `dates` URL param round-trips
through the codec and is clamped to [today, today + 12 months]; a reversed
or malformed value collapses to no restriction. `dateRange` is counted in
`activeFilterCount` and keyed in `filtersKey`, and `useSetFilters` gains a
`setDateRange`. `dateWindow()` is shared by the codec clamp and the picker.

Updates the ActiveFilterPills story literal for the new required field.

Closes #48

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
label / from / to / pill_from / pill_until / pill_range for the date
filter, in all 10 locales (cs de en es fr hu nl pt-BR ru uk). Ruby-style
%{} interpolation; no `count` variable (avoids i18next pluralization).

#48

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
SearchFilters gains a Date group: two native `<input type="date">` (From /
To) bounded to [today, today + 12 months] via `dateWindow()`, with the To
min following From and vice-versa, wired through the draft `patch` flow.
ActiveFilterPills shows the applied range as one collapsed, removable pill
(locale-aware luxon `DATE_MED`: "From …", "Until …", or "… – …") whose X
clears the group via `setDateRange`.

#48

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- filtersKey: pass `dateRange` directly instead of a redundant [start, end]
  tuple — a DateRange is always {start, end}, so JSON.stringify is stable
  (matches how timeOfDay is keyed).
- SearchFilters: extract a module-private DateBound for the From/To inputs
  (mirrors the file's FilterGroup helper), so the input styling lives once.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A native date input enforces its min/max only in the calendar UI, not for
keyboard entry — so a typed out-of-window or reversed value could make the
draft's live "Apply (N)" count disagree with the applied result (the URL
codec clamps the window and collapses a reversed range on read). Clamp each
typed value to the input's own [min, max] in DateBound so the draft stays in
step with what applies. Found in the /code-review pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3b80618
Status: ✅  Deploy successful!
Preview URL: https://60bfb6ad.sahajatlas-design.pages.dev
Branch Preview URL: https://feat-date-range-filter.sahajatlas-design.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6e91bd2
Status:⚡️  Build in progress...

View logs

An open-ended "until Y" date range (only the To date set) had no lower
bound, so a stale- or timezone-shifted `upcomingDates` occurrence dated
before today could still match — most visibly for an online event whose
next occurrence reads as "yesterday" in the viewer's zone near midnight.
Floor the lower bound at today in matchesFilters (a set start is already
clamped to >= today), injecting `today` so the predicate stays pure and the
map's hot path reads the clock once per feed rather than per feature.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit 2f10267 into main Jul 14, 2026
2 of 3 checks passed
@Ardnived
Ardnived deleted the feat/date-range-filter branch July 14, 2026 16:47
Ardnived added a commit that referenced this pull request Jul 14, 2026
Brings in #49 (pin-hover highlight) and #50 (date-range filter). Two
conflicts, resolved by combining both sides:
- Map.tsx `filtered` memo + fetch.ts `getEvents`: keep #50's `today` arg to
  matchesFilters AND this branch's geometry-only toMapSource trim /
  per-locale titles join.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(search): filter events by a date range

1 participant