From 1246c8382c8734dc705f96bf9fa6b5efdd3819bc Mon Sep 17 00:00:00 2001 From: yyamashita Date: Fri, 8 May 2026 08:38:32 +0900 Subject: Fix all TODO bugs and implement feature additions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SCRAPE_TARGETS.md: add 5 missing venues (nine-spices, nishieifuku-jam, fever-shindaita, moon-step-nakano, mod-shibasaki) - Navigation: add 日付別 link to venues.tsx and events.$id.tsx headers - venues.tsx: add official site external links per venue card - ScrapeButton: new component with useFetcher-based trigger + 2s polling progress UI showing per-venue status and event count - venues.tsx / events._index.tsx: wire in ScrapeButton - FilterBar + db.server.ts: add area filter derived from venues, threaded through queryEvents Co-Authored-By: Claude Sonnet 4.6 --- app/components/FilterBar.tsx | 24 ++++++++- app/components/ScrapeButton.tsx | 115 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 app/components/ScrapeButton.tsx (limited to 'app/components') diff --git a/app/components/FilterBar.tsx b/app/components/FilterBar.tsx index 7b8ca0c..7a95d2c 100644 --- a/app/components/FilterBar.tsx +++ b/app/components/FilterBar.tsx @@ -3,11 +3,12 @@ import type { Venue } from "~/lib/db.server"; interface Props { venues: Venue[]; + areas?: string[]; defaultDateFrom?: string; defaultDateTo?: string; } -export default function FilterBar({ venues, defaultDateFrom, defaultDateTo }: Props) { +export default function FilterBar({ venues, areas, defaultDateFrom, defaultDateTo }: Props) { const [searchParams] = useSearchParams(); return ( @@ -63,6 +64,25 @@ export default function FilterBar({ venues, defaultDateFrom, defaultDateTo }: Pr /> + {/* Area */} + {areas && areas.length > 0 && ( +
+ + +
+ )} + {/* Capacity */}
@@ -98,5 +118,5 @@ export default function FilterBar({ venues, defaultDateFrom, defaultDateTo }: Pr } function hasFilters(params: URLSearchParams): boolean { - return ["keyword", "venue_id", "date_from", "date_to", "capacity_range"].some((k) => params.get(k)); + return ["keyword", "venue_id", "date_from", "date_to", "capacity_range", "area"].some((k) => params.get(k)); } diff --git a/app/components/ScrapeButton.tsx b/app/components/ScrapeButton.tsx new file mode 100644 index 0000000..75e48b1 --- /dev/null +++ b/app/components/ScrapeButton.tsx @@ -0,0 +1,115 @@ +import { useState, useEffect, useRef } from "react"; +import { useFetcher } from "react-router"; + +interface ScrapeLog { + id: number; + run_id: string; + venue_id: string; + venue_name: string; + status: "running" | "ok" | "error"; + events_saved: number; + error: string | null; +} + +interface StatusData { + running: boolean; + results: ScrapeLog[]; +} + +interface ScrapeStartData { + run_id: string; + status: string; +} + +export default function ScrapeButton({ venueId }: { venueId?: string }) { + const triggerFetcher = useFetcher(); + const statusFetcher = useFetcher(); + const statusFetcherRef = useRef(statusFetcher); + useEffect(() => { statusFetcherRef.current = statusFetcher; }); + + const [runId, setRunId] = useState(null); + const [polling, setPolling] = useState(false); + const [done, setDone] = useState(false); + + useEffect(() => { + const data = triggerFetcher.data; + if (data?.run_id) { + setRunId(data.run_id); + setPolling(true); + setDone(false); + } + }, [triggerFetcher.data]); + + useEffect(() => { + if (!polling || !runId) return; + const id = setInterval(() => { + statusFetcherRef.current.load(`/api/scrape-status?run_id=${runId}`); + }, 2000); + return () => clearInterval(id); + }, [polling, runId]); + + useEffect(() => { + const data = statusFetcher.data; + if (data && !data.running) { + setPolling(false); + setDone(true); + } + }, [statusFetcher.data]); + + const results: ScrapeLog[] = statusFetcher.data?.results ?? []; + const running = statusFetcher.data?.running ?? false; + const isActive = triggerFetcher.state !== "idle" || polling; + const okCount = results.filter((r) => r.status === "ok").length; + const errCount = results.filter((r) => r.status === "error").length; + const apiUrl = venueId ? `/api/scrape?venue_id=${venueId}` : "/api/scrape"; + + return ( +
+ + + {(isActive || done) && results.length > 0 && ( +
+

+ {running + ? `スクレイプ中... ${okCount + errCount} / ${results.length} 完了` + : `完了 — ✔ ${okCount}件成功 / ✖ ${errCount}件失敗`} +

+ {results.map((r) => ( +
+ + {r.status === "ok" ? "✔" : r.status === "error" ? "✖" : "⟳"} + + {r.venue_name} + {r.status === "ok" && ( + {r.events_saved}件 + )} + {r.status === "error" && ( + + エラー + + )} +
+ ))} +
+ )} +
+ ); +} -- cgit v1.2.3