Merge branch 'main' of http://103.107.52.82:3004/at-transit/web-at-transit
This commit is contained in:
commit
9519fef02d
174 files changed
+5964
-27
No files matched your search
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
import HomeView from "@/components/views/HomeView";
|
||||
import PageRuntime from "@/components/PageRuntime";
|
||||
|
||||
@@ -19,6 +20,64 @@ export default async function Page({
|
||||
<>
|
||||
<HomeView />
|
||||
<PageRuntime page="home" query={query} />
|
||||
=======
|
||||
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<string, string[]> = {};
|
||||
for (const s of schedules) {
|
||||
(timesByRoute[s.route_id] ??= []).push(...s.departure_times);
|
||||
}
|
||||
|
||||
// route_id -> station ids (for station-level filtering)
|
||||
const routeStations: Record<string, number[]> = {};
|
||||
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 (
|
||||
<>
|
||||
<VisitTracker path="/" />
|
||||
<HomeClient
|
||||
groups={groups}
|
||||
routes={routes}
|
||||
timesByRoute={timesByRoute}
|
||||
provinces={provinces}
|
||||
stops={stops}
|
||||
routeStations={routeStations}
|
||||
initialProvinceId={initialProvinceId}
|
||||
initialStationCode={initialStationCode}
|
||||
/>
|
||||
>>>>>>> 1526c5b6d06989ba2d865f6df4d339d680dbd3f8
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user