2024-04-17 12:20:29 +01:00
|
|
|
<script lang="ts">
|
2024-04-30 11:17:06 +01:00
|
|
|
import Header from "$lib/navigation/header.svelte";
|
|
|
|
import Loading from "$lib/navigation/loading.svelte";
|
|
|
|
import Island from "$lib/islands/island.svelte";
|
|
|
|
import Nav from "$lib/navigation/nav.svelte";
|
|
|
|
import { uuid } from "$lib/stores/uuid";
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2024-04-30 11:17:06 +01:00
|
|
|
import { onMount } from "svelte";
|
|
|
|
import TrainDetail from "$lib/train/train-detail.svelte";
|
|
|
|
import { getApiUrl } from "$lib/scripts/upstream";
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2024-04-30 11:17:06 +01:00
|
|
|
let title = "Timetable Results";
|
|
|
|
let id = "";
|
|
|
|
let data = [];
|
|
|
|
let isLoading = true;
|
|
|
|
let error = false;
|
|
|
|
let errMsg = "";
|
2023-06-20 19:22:59 +01:00
|
|
|
|
2024-04-30 11:17:06 +01:00
|
|
|
$: {
|
|
|
|
if (id) {
|
|
|
|
title = id.toUpperCase();
|
|
|
|
} else {
|
|
|
|
title = "Querying Timetable";
|
|
|
|
}
|
2023-06-13 13:38:59 +01:00
|
|
|
}
|
|
|
|
|
2024-04-30 11:17:06 +01:00
|
|
|
async function getHeadcode() {
|
|
|
|
return new URLSearchParams(window.location.search).get("headcode");
|
2023-07-07 11:27:28 +01:00
|
|
|
}
|
2023-06-19 21:55:23 +01:00
|
|
|
|
2024-04-30 11:17:06 +01:00
|
|
|
onMount(async () => {
|
|
|
|
isLoading = true;
|
|
|
|
id = (await getHeadcode()) || "";
|
|
|
|
const res = await fetchData(id);
|
|
|
|
if (res) {
|
|
|
|
data = res;
|
|
|
|
if (!data.length) {
|
|
|
|
error = true;
|
|
|
|
errMsg = "No services found";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isLoading = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
async function fetchData(id = "") {
|
|
|
|
const date = "now";
|
|
|
|
const searchType = "headcode";
|
|
|
|
const options = {
|
|
|
|
method: "GET",
|
|
|
|
headers: {
|
2024-04-30 11:18:21 +01:00
|
|
|
uuid: $uuid,
|
|
|
|
},
|
2024-04-30 11:17:06 +01:00
|
|
|
};
|
|
|
|
const url = `${getApiUrl()}/api/v2/timetable/train/${date}/${searchType}/${id}`;
|
|
|
|
try {
|
|
|
|
const res = await fetch(url, options);
|
|
|
|
if (res.status == 200) {
|
|
|
|
return await res.json();
|
|
|
|
} else if (res.status === 401) {
|
|
|
|
error = true;
|
|
|
|
errMsg = "You must be logged into the staff version for this feature";
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
errMsg = "Unable to connect, check your connection and try again";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
error = true;
|
|
|
|
errMsg = "Connection error, try again later";
|
|
|
|
}
|
|
|
|
isLoading = false;
|
2023-07-08 21:54:33 +01:00
|
|
|
}
|
2023-06-19 21:55:23 +01:00
|
|
|
</script>
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-06-19 21:55:23 +01:00
|
|
|
<Header {title} />
|
2023-07-07 11:27:28 +01:00
|
|
|
<div id="whitespace" />
|
2023-06-26 15:34:01 +01:00
|
|
|
|
2023-06-27 12:38:41 +01:00
|
|
|
{#if error}
|
2024-04-30 11:17:06 +01:00
|
|
|
<Island>
|
|
|
|
<p style="font-weight:600">{errMsg}</p>
|
|
|
|
</Island>
|
2023-06-27 12:38:41 +01:00
|
|
|
{/if}
|
|
|
|
|
2023-06-26 15:34:01 +01:00
|
|
|
{#if isLoading}
|
2024-04-30 11:17:06 +01:00
|
|
|
<Loading />
|
2023-06-26 15:34:01 +01:00
|
|
|
{/if}
|
2023-07-07 11:27:28 +01:00
|
|
|
|
2023-06-19 21:55:23 +01:00
|
|
|
{#each data as service}
|
2024-04-30 11:17:06 +01:00
|
|
|
{#if service}
|
|
|
|
<TrainDetail {service} />
|
|
|
|
{/if}
|
2023-06-19 21:55:23 +01:00
|
|
|
{/each}
|
2023-07-07 11:27:28 +01:00
|
|
|
|
2023-06-20 19:22:59 +01:00
|
|
|
<Nav />
|
|
|
|
|
|
|
|
<style>
|
2024-04-30 11:17:06 +01:00
|
|
|
#whitespace {
|
|
|
|
height: 15px;
|
|
|
|
}
|
|
|
|
p {
|
|
|
|
color: white;
|
|
|
|
font-size: 18px;
|
|
|
|
font-weight: 600;
|
|
|
|
}
|
2023-07-07 11:27:28 +01:00
|
|
|
</style>
|