2023-06-13 13:38:59 +01:00
|
|
|
<script>
|
2023-06-15 21:32:14 +01:00
|
|
|
import Header from '$lib/navigation/header.svelte'
|
2023-06-26 15:34:01 +01:00
|
|
|
import Loading from '$lib/navigation/loading.svelte';
|
2023-06-27 12:38:41 +01:00
|
|
|
import Island from '$lib/islands/island.svelte';
|
2023-06-26 15:34:01 +01:00
|
|
|
import Nav from '$lib/navigation/nav.svelte';
|
|
|
|
import { uuid } from '$lib/stores/uuid';
|
2023-06-13 13:38:59 +01:00
|
|
|
|
|
|
|
import { onMount } from 'svelte'
|
2023-06-30 11:08:59 +01:00
|
|
|
import TrainDetail from '$lib/train/train-detail.svelte';
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-06-19 21:55:23 +01:00
|
|
|
let title = "Timetable Results"
|
|
|
|
let id = ""
|
|
|
|
let data = [];
|
2023-06-26 15:34:01 +01:00
|
|
|
let isLoading = true;
|
2023-06-27 12:38:41 +01:00
|
|
|
let error = false;
|
|
|
|
let errMsg = "";
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-06-20 19:22:59 +01:00
|
|
|
$: {
|
|
|
|
if (id) {
|
|
|
|
title = id.toUpperCase();
|
|
|
|
} else {
|
|
|
|
title = "Querying Timetable"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-13 13:38:59 +01:00
|
|
|
async function getHeadcode() {
|
|
|
|
return new URLSearchParams(window.location.search).get('headcode');
|
|
|
|
}
|
|
|
|
|
|
|
|
onMount(async () => {
|
2023-06-26 15:34:01 +01:00
|
|
|
isLoading = true;
|
2023-06-19 21:55:23 +01:00
|
|
|
id = await getHeadcode() || "";
|
2023-06-27 12:38:41 +01:00
|
|
|
const res = await fetchData(id);
|
|
|
|
if (res) {
|
|
|
|
data = res;
|
2023-06-28 12:43:32 +01:00
|
|
|
if (!data.length) {
|
|
|
|
error = true;
|
|
|
|
errMsg = "No services found"
|
|
|
|
}
|
2023-06-27 12:38:41 +01:00
|
|
|
}
|
|
|
|
isLoading = false;
|
2023-06-13 13:38:59 +01:00
|
|
|
})
|
|
|
|
|
2023-06-19 21:55:23 +01:00
|
|
|
async function fetchData(id = "") {
|
|
|
|
const date = 'now';
|
|
|
|
const searchType = 'headcode'
|
2023-06-26 15:34:01 +01:00
|
|
|
const options = {
|
|
|
|
method: "GET",
|
|
|
|
headers: {
|
|
|
|
"uuid": $uuid
|
|
|
|
}
|
|
|
|
}
|
2023-06-19 21:55:23 +01:00
|
|
|
const url = `https://owlboard.info/api/v2/timetable/train/${date}/${searchType}/${id}`
|
2023-06-26 15:34:01 +01:00
|
|
|
const res = await fetch(url, options);
|
2023-06-27 12:38:41 +01:00
|
|
|
isLoading = false;
|
|
|
|
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;
|
|
|
|
}
|
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-06-30 11:08:59 +01:00
|
|
|
<div id="whitespace"></div>
|
2023-06-26 15:34:01 +01:00
|
|
|
|
2023-06-27 12:38:41 +01:00
|
|
|
{#if error}
|
|
|
|
<Island>
|
|
|
|
<p class="error">{errMsg}</p>
|
|
|
|
</Island>
|
|
|
|
{/if}
|
|
|
|
|
2023-06-26 15:34:01 +01:00
|
|
|
{#if isLoading}
|
|
|
|
<Loading />
|
|
|
|
{/if}
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-06-19 21:55:23 +01:00
|
|
|
{#each data as service}
|
2023-06-30 11:08:59 +01:00
|
|
|
<TrainDetail {service} />
|
2023-06-19 21:55:23 +01:00
|
|
|
{/each}
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-06-20 19:22:59 +01:00
|
|
|
<Nav />
|
|
|
|
|
|
|
|
<style>
|
2023-06-30 11:08:59 +01:00
|
|
|
#whitespace {
|
|
|
|
height: 15px;
|
2023-06-20 19:22:59 +01:00
|
|
|
}
|
|
|
|
p {
|
2023-06-20 19:24:17 +01:00
|
|
|
color: white;
|
2023-06-21 20:55:31 +01:00
|
|
|
font-size: 18px;
|
2023-06-20 19:22:59 +01:00
|
|
|
font-weight: 600;
|
|
|
|
}
|
|
|
|
</style>
|