Refactor mobile UI and centralize HAFAS parsing
Introduce useColors hook to replace direct theme usage in mobile screens. Extract EventHeader, JourneyList, BikeSection, and NearbyStops components to reduce complexity in EventDetailScreen. Move parseHafasJourneys to packages/core for shared usage between web and mobile clients. Update web API route with stricter HAFAS validation and consistent client instantiation. Add comprehensive codebase function guide documenting data flow, shared packages, and service integrations.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import type { Journey } from "./types";
|
||||
import { parseHafasTime } from "./hafas-time";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type RawJson = any;
|
||||
|
||||
export function parseHafasJourneys(json: RawJson, hafasDate: string, queryDate: Date): Journey[] {
|
||||
const outConL: RawJson[] = json?.svcResL?.[0]?.res?.outConL ?? [];
|
||||
|
||||
return outConL.map((con: RawJson, i: number): Journey => {
|
||||
const first = con.secL?.[0];
|
||||
const last = con.secL?.[con.secL.length - 1];
|
||||
const dep = first?.dep;
|
||||
const arr = last?.arr;
|
||||
|
||||
const sD = dep?.dTimeS ? parseHafasTime(hafasDate, dep.dTimeS) : queryDate;
|
||||
const rD = dep?.dTimeR ? parseHafasTime(hafasDate, dep.dTimeR) : sD;
|
||||
const sA = arr?.aTimeS ? parseHafasTime(hafasDate, arr.aTimeS) : sD;
|
||||
const rA = arr?.aTimeR ? parseHafasTime(hafasDate, arr.aTimeR) : sA;
|
||||
|
||||
const delay = Math.max(0, Math.round((rD.getTime() - sD.getTime()) / 60000));
|
||||
const trains: string[] = (con.secL ?? [])
|
||||
.filter((s: RawJson) => s.jny)
|
||||
.map((s: RawJson) => s.jny?.stopL?.[0]?.name ?? "")
|
||||
.filter(Boolean);
|
||||
|
||||
return {
|
||||
id: con.ctxRecon ?? `journey-${i}`,
|
||||
sD, rD, sA, rA, delay,
|
||||
platform: dep?.dPlatfS ?? "",
|
||||
changes: Math.max(0, (con.secL ?? []).filter((s: RawJson) => s.jny).length - 1),
|
||||
trains,
|
||||
cancelled: (con.secL ?? []).some((s: RawJson) => s.jny?.isCncl === true),
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -4,3 +4,4 @@ export * from './countdown-utils';
|
||||
export * from './formatting';
|
||||
export * from './status-utils';
|
||||
export * from './hafas-time';
|
||||
export * from './hafas-parser';
|
||||
|
||||
Reference in New Issue
Block a user