Skip to content

Shared Map/Explore filters - #74

Merged
yubimamiya merged 1 commit into
stagingfrom
yubi_11-30_datefilter
Nov 30, 2026
Merged

yubimamiya merged 1 commit into
stagingfrom
yubi_11-30_datefilter

Conversation

@yubimamiya

Copy link
Copy Markdown

Shared date & activity filters for Map and Explore

Follow-up to #73 (Map UI redesign). The Map's filters used to reset whenever you opened an event and came back, and Explore had no date filter at all. This PR makes the date range and the Friends Going / Happening Now chips one set of filters shared by the Map and Explore, adds a reset button to both pages, and fixes two time bugs along the way.

What changed

Filters carry across pages

  • The date range, Friends Going and Happening Now are now one shared set of filters for the Map and Explore. Changing them on one page changes them on the other.
  • They're kept when you open an event and go back, move around with the sidebar, or reload the page.
  • They're stored in a cookie that ends when the browser closes. The CAS login and logout routes clear it, so every visit starts on "All dates".
  • Search text and topic chips still belong to each page.

Explore

  • Friends Going / Happening Now chips sit below the search bar and above the topics. They're the same component as on the Map, moved from map/_components/map-filter-pills.tsx to components/events/activity-filter-pills.tsx.
  • A date-range picker sits under the topics. It's a popover with the existing shadcn Calendar and quick picks (Today, This week, Next 7 days, All dates). Only today through 14 days ahead can be picked, the same 15 days as the Map timeline.
  • All three filters run in the feed query (loadRankedFeed), not in the browser, so "N events match" and "Load more" stay correct.
  • Explore's first page loads already filtered, because the server reads the cookie. If Back/Forward restores a cached copy built with older filters, it refetches.

Reset button (Map and Explore)

  • A ↺ button next to the search bar clears the search, topics, Friends Going, Happening Now and dates.
  • It's disabled when nothing is filtered.

Time fixes

  • Map day boundaries. getMapEvents used setHours(0, 0, 0, 0), which follows the server's time zone. On a UTC server, "today" started at 7 PM Eastern the evening before, and the last day's evening events were dropped. It now uses Princeton calendar days. It also now includes multi-day events that started before today but are still running.
  • Happening Now. It used to mean "started within the last 2 hours". It now means "started and hasn't ended", using the event's end time, with 2 hours assumed only when there's no end time. The rule lives in one place, lib/happening-now.ts, and the Map and the feed query both use it. Map pins now turn coral if any event at that spot is happening now, not just the first one.

Implementation notes

  • lib/event-filters.ts holds the shared filter types, the 15-day window, cookie parsing/serializing, and clampRange.
    • A start date that has passed (for example, a tab left open overnight) moves up to today.
    • A range covering the whole window counts as "All dates".
  • components/providers/event-filters-provider.tsx holds the filters for the whole app. It's mounted in app/(app)/layout.tsx and seeded from the cookie.
  • getFeedEvents takes new optional from / to (YYYY-MM-DD, validated, from <= to) plus friendsGoing and happeningNow. Dates are converted to Princeton midnight with zonedDateTimeToDate.
  • loadRankedFeed:
    • Happening Now replaces the usual "hasn't started yet" condition with "started and not yet ended".
    • Friends Going uses an rsvps subquery over the friend IDs the feed already loads.
    • The date range only adds a lower bound when the range starts after today. In-progress events count as today's, which matches how the Map counts them.
  • map/_lib/map-types.ts no longer defines DateRange; it now lives in lib/event-filters.ts.
  • TIMELINE_DAYS is now set from FILTER_WINDOW_DAYS (still 15).

Testing

  • bun run check, tsc --noEmit and bun run test pass. New unit tests are in lib/event-filters.test.ts and lib/happening-now.test.ts.
  • feed-controls.db.test.ts passes against a local database (7/7). It covers sorts, paging, hidden orgs and the map query.
  • Ran the real feed query with the clock set to 4:45 PM Eastern:
    • Happening Now returned exactly the two 4:30–6:00 PM events.
    • With a range starting tomorrow, it returned none.
    • A "Tue 12/1" range returned only Dec 1 events, including a 7:00 PM one that the old UTC cut-off would have dropped.
  • Logged-in browser checks:
    • Set the filters on the Map, went to Explore through the sidebar: same filters, feed filtered.
    • Changed the range on Explore and went back to the Map: the timeline matched.
    • Reloaded: filters kept.
    • Went "See Details" → Back from both the Map and Explore: range kept.
    • Pressed reset on both pages: everything cleared and the cookie was removed.
    • No console errors.
    • The reset on login.
  • Not tested:
  • Friends Going with real friend data.
  • feed-recommendations.db.test.ts, which needs its own database URL.

To try it

  1. On /map, pick a date range on the timeline and turn on Happening Now.
  2. Click "Home" in the sidebar. Explore should show the same chips and the same date range, and the feed should be filtered.
  3. Open an event's "See Details", then go Back. The filters should still be set.
  4. Change the dates with Explore's picker, then go back to the Map. The timeline should match.
  5. Press ↺ on either page. Everything should clear on both.
  6. Log out and back in. You should start on "All dates".

… fixes

- Date range, Friends Going and Happening Now are one shared filter state
  for the Map and Explore (EventFiltersProvider in the app layout, seeded
  from a session cookie). They survive opening an event and going back,
  sidebar navigation and reloads; the CAS login/logout routes clear them
  so each visit starts on "All dates".
- Explore: Friends Going / Happening Now chips (shared component with the
  Map) above the topics, and a date-range picker below them limited to the
  Map timeline's 15 days. All three filter server-side in loadRankedFeed,
  so counts and "Load more" stay correct.
- Reset button beside the search bar on both pages clears search, topics,
  Friends Going, Happening Now and dates.
- Happening Now is "started and not yet ended" using the event's end time
  (2h fallback when it has none), shared by the Map and the feed query.
- getMapEvents uses Princeton day bounds instead of the server's local
  midnight, which on UTC servers started "today" at 7 PM Eastern the day
  before and cut off the last day's evening; also includes multi-day
  events still in progress.
- Tests for cookie parsing/clamping and the Happening Now rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yubimamiya
yubimamiya merged commit 7e897d0 into staging Nov 30, 2026
1 check passed
@yubimamiya
yubimamiya deleted the yubi_11-30_datefilter branch November 30, 2026 16:43
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.

1 participant