From c18885f2b022f4a8116809aa893929f2c278b319 Mon Sep 17 00:00:00 2001
From: yyamashita <yyamashita@mosquit.one>
Date: Wed, 6 May 2026 22:09:41 +0900
Subject: 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>
---
 app/routes/events._index.tsx | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

(limited to 'app/routes/events._index.tsx')

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">
-- 
cgit v1.2.3

