2023-06-13 13:38:59 +01:00
|
|
|
<script>
|
2023-07-07 11:27:28 +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
|
|
|
|
2023-07-07 11:27:28 +01:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
import TrainDetail from '$lib/train/train-detail.svelte';
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-07-07 11:27:28 +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
|
|
|
|
2023-07-07 11:27:28 +01:00
|
|
|
$: {
|
|
|
|
if (id) {
|
|
|
|
title = id.toUpperCase();
|
|
|
|
} else {
|
|
|
|
title = 'Querying Timetable';
|
2023-06-13 13:38:59 +01:00
|
|
|
}
|
2023-07-07 11:27:28 +01:00
|
|
|
}
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-07-07 11:27:28 +01:00
|
|
|
async function getHeadcode() {
|
|
|
|
return new URLSearchParams(window.location.search).get('headcode');
|
|
|
|
}
|
2023-06-13 13:38:59 +01:00
|
|
|
|
2023-07-07 11:27:28 +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;
|
|
|
|
});
|
2023-06-19 21:55:23 +01:00
|
|
|
|
2023-07-07 11:27:28 +01:00
|
|
|
async function fetchData(id = '') {
|
|
|
|
const date = 'now';
|
|
|
|
const searchType = 'headcode';
|
|
|
|
const options = {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
uuid: $uuid
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const url = `https://owlboard.info/api/v2/timetable/train/${date}/${searchType}/${id}`;
|
2023-07-08 21:54:33 +01:00
|
|
|
try {
|
|
|
|
const res = await fetch(url, options);
|
2023-07-09 08:12:25 +01:00
|
|
|
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-07-08 21:54:33 +01:00
|
|
|
} catch (err) {
|
|
|
|
error = true;
|
|
|
|
errMsg = 'Connection error, try again later';
|
|
|
|
}
|
2023-07-07 11:27:28 +01:00
|
|
|
isLoading = 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-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}
|
2023-07-07 11:27:28 +01:00
|
|
|
<Island>
|
2023-07-08 21:54:33 +01:00
|
|
|
<p style="font-weight:600">{errMsg}</p>
|
2023-07-07 11:27:28 +01:00
|
|
|
</Island>
|
2023-06-27 12:38:41 +01:00
|
|
|
{/if}
|
|
|
|
|
2023-06-26 15:34:01 +01:00
|
|
|
{#if isLoading}
|
|
|
|
<Loading />
|
|
|
|
{/if}
|
2023-07-07 11:27:28 +01:00
|
|
|
|
2023-06-19 21:55:23 +01:00
|
|
|
{#each data as service}
|
2023-07-11 22:59:41 +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>
|
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;
|
|
|
|
}
|
2023-07-07 11:27:28 +01:00
|
|
|
</style>
|