<<<<<<< HEAD import HomeView from "@/components/views/HomeView"; import PageRuntime from "@/components/PageRuntime"; export const metadata = { title: "หน้าแรก" }; export default async function Page({ searchParams, }: { searchParams: Promise>; }) { const sp = await searchParams; const query: Record = {}; // ลิงก์สั้นเดิม: #/?s=<รหัสสถานี> และ #/?p= for (const key of ["s", "p"]) { const value = sp[key]; if (typeof value === "string") query[key] = value; } return ( <> ======= import { api, type RouteListItem, type Schedule } from "@/lib/api"; import { VisitTracker } from "@/lib/visit-tracker"; import HomeClient from "@/components/HomeClient"; export default async function HomePage({ searchParams, }: { searchParams: Promise<{ p?: string; s?: string }>; }) { const sp = await searchParams; const [groupsRes, routesRes, schedRes, provRes, stopsRes] = await Promise.allSettled([ api.routeGroups(), api.routes(), api.schedules({}), api.provinces(), api.stops(), ]); const groups = groupsRes.status === "fulfilled" ? groupsRes.value.items : []; const routes: RouteListItem[] = routesRes.status === "fulfilled" ? routesRes.value.items : []; const schedules: Schedule[] = schedRes.status === "fulfilled" ? schedRes.value.items : []; const provinces = provRes.status === "fulfilled" ? provRes.value.items : []; const stops = stopsRes.status === "fulfilled" ? stopsRes.value.items : []; // route_id -> all departure times const timesByRoute: Record = {}; for (const s of schedules) { (timesByRoute[s.route_id] ??= []).push(...s.departure_times); } // route_id -> station ids (for station-level filtering) const routeStations: Record = {}; await Promise.all( routes.map(async (r) => { const { items } = await api.routeStops(r.route_id).catch(() => ({ items: [] })); routeStations[r.route_id] = items.map((x) => x.station_id); }), ); const initialProvinceId = sp.p ? Number(sp.p) || undefined : undefined; const initialStationCode = sp.s ?? undefined; return ( <> >>>>>>> 1526c5b6d06989ba2d865f6df4d339d680dbd3f8 ); }