diff options
| author | yyamashita <yyamashita@mosquit.one> | 2026-05-06 22:09:41 +0900 |
|---|---|---|
| committer | yyamashita <yyamashita@mosquit.one> | 2026-05-06 22:09:41 +0900 |
| commit | c18885f2b022f4a8116809aa893929f2c278b319 (patch) | |
| tree | c2818ef46ff58c7e3bc4cb2bd9b8a48e5821c3f8 /app/routes | |
| parent | be55729482296663da8c96723bfd22080e6762c1 (diff) | |
Limit scrape window and default event list to ~1 month
Scraper runner now filters events to today + 35 days before upserting,
so the DB only holds the upcoming month of events.
Event list loader defaults date_from/date_to to the same window when
no query params are set, and passes the values down to FilterBar so the
date inputs are pre-filled on first load.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'app/routes')
| -rw-r--r-- | app/routes/events._index.tsx | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/app/routes/events._index.tsx b/app/routes/events._index.tsx index 3883d37..3ff441a 100644 --- a/app/routes/events._index.tsx +++ b/app/routes/events._index.tsx @@ -4,10 +4,22 @@ import { queryEvents, getVenues } from "~/lib/db.server"; import EventCard from "~/components/EventCard"; import FilterBar from "~/components/FilterBar"; +function defaultWindow() { + const today = new Date(); + today.setHours(0, 0, 0, 0); + const end = new Date(today); + end.setDate(end.getDate() + 35); + return { + from: today.toISOString().slice(0, 10), + to: end.toISOString().slice(0, 10), + }; +} + export async function loader({ request }: Route.LoaderArgs) { const url = new URL(request.url); - const date_from = url.searchParams.get("date_from") ?? undefined; - const date_to = url.searchParams.get("date_to") ?? undefined; + const { from: defaultFrom, to: defaultTo } = defaultWindow(); + const date_from = url.searchParams.get("date_from") ?? defaultFrom; + const date_to = url.searchParams.get("date_to") ?? defaultTo; const venue_id = url.searchParams.get("venue_id") ?? undefined; const keyword = url.searchParams.get("keyword") ?? undefined; const page = Math.max(1, parseInt(url.searchParams.get("page") ?? "1", 10)); @@ -17,11 +29,11 @@ export async function loader({ request }: Route.LoaderArgs) { const events = queryEvents({ date_from, date_to, venue_id, keyword, limit, offset }); const venues = getVenues(); - return { events, venues, page, hasMore: events.length === limit }; + return { events, venues, page, hasMore: events.length === limit, date_from, date_to }; } export default function EventsIndex() { - const { events, venues, page, hasMore } = useLoaderData<typeof loader>(); + const { events, venues, page, hasMore, date_from, date_to } = useLoaderData<typeof loader>(); const [searchParams] = useSearchParams(); return ( @@ -49,7 +61,7 @@ export default function EventsIndex() { </Form> </div> - <FilterBar venues={venues} /> + <FilterBar venues={venues} defaultDateFrom={date_from} defaultDateTo={date_to} /> {events.length === 0 ? ( <div className="mt-16 text-center text-gray-500"> |
