Skip to content

Commit c400eb7

Browse files
committed
frontend: remove dynamic updating of journeys
- INFO: for the time being
1 parent 06911ab commit c400eb7

File tree

3 files changed

+38
-42
lines changed

3 files changed

+38
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
11
import type { PageServerLoad } from "./$types";
22
import type { Station } from "$models/station";
33
import { error } from "@sveltejs/kit";
4+
import type { Journey } from "$models/connection";
5+
import { DateTime } from "luxon";
46

5-
export const load: PageServerLoad = async ({ fetch, params }): Promise<{ station: Station }> => {
6-
const response = await fetch(`http://navigator-backend:8000/api/v1/stations/${params.evaNumber}`, {
7+
export const load: PageServerLoad = async ({ params, url }): Promise<{ station: Station, journeys: Journey[] }> => {
8+
const [station, journeys] = await Promise.all([
9+
loadStation(params.evaNumber),
10+
loadJourneys(params.evaNumber, params.type, url.searchParams.get("startDate") ?? DateTime.now().set({ second: 0, millisecond: 0 }).toISO())
11+
]);
12+
return { station, journeys };
13+
};
14+
15+
const loadStation = async (evaNumber: string): Promise<Station> => {
16+
const response = await fetch(`http://navigator-backend:8000/api/v1/stations/${evaNumber}`, {
717
method: "GET"
818
});
9-
1019
if (!response.ok) {
11-
throw error(404, `No station found for ${params.evaNumber}`);
20+
throw error(404, `No station found for ${evaNumber}`);
1221
}
1322

1423
const station = (await response.json()) as Station;
15-
1624
if (station.evaNumber === undefined) {
17-
throw error(404, `No station found for ${params.evaNumber}`);
25+
throw error(404, `No station found for ${evaNumber}`);
1826
}
19-
20-
return { station: station };
27+
return station;
2128
};
29+
30+
const loadJourneys = async (evaNumber: string, type: string, startDate: string): Promise<Journey[]> => {
31+
const queryString = new URLSearchParams({
32+
evaNumber: evaNumber,
33+
type: type,
34+
when: startDate
35+
}).toString();
36+
37+
const response = await fetch(`http://navigator-backend:8000/api/v1/timetable/combined?${queryString}`, {
38+
method: "GET"
39+
});
40+
if (!response.ok) {
41+
throw error(404, `No journeys found for ${evaNumber}`);
42+
}
43+
44+
const jsonData = await response.json();
45+
if (!Array.isArray(jsonData)) {
46+
throw error(500, `No journeys found for ${evaNumber}`);
47+
}
48+
49+
return jsonData as Journey[];
50+
}

frontend/src/routes/[evaNumber]/[type=type]/+page.svelte

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
2-
import { invalidateAll } from "$app/navigation";
3-
import { onDestroy, onMount, setContext } from "svelte";
2+
import { setContext } from "svelte";
43
import { MetaTags } from "svelte-meta-tags";
54
import type { PageProps } from "./$types";
65
import Clock from "$components/timetable/Clock.svelte";
@@ -24,11 +23,6 @@
2423
2524
return currentFilter.includes(firstConnection?.lineInformation?.type ?? "");
2625
};
27-
28-
onMount(() => {
29-
const interval = setInterval(() => invalidateAll(), 30 * 1000);
30-
onDestroy(() => clearInterval(interval));
31-
});
3226
</script>
3327

3428
<MetaTags

frontend/src/routes/[evaNumber]/[type=type]/+page.ts

-27
This file was deleted.

0 commit comments

Comments
 (0)