Compare commits

...

5 Commits

9 changed files with 611 additions and 159 deletions

View File

@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import type { ApiStationsBoard } from '@owlboard/owlboard-ts'; import type { ApiStationsBoard } from '@owlboard/owlboard-ts';
import { formatUkTime, estClass, calculateDelay } from '$lib/utils/time'; import { formatUkTime, estClass, delayClassFromTimePair } from '$lib/utils/time';
let { services }: { services: ApiStationsBoard.BoardService[] } = $props(); let { services }: { services: ApiStationsBoard.BoardService[] } = $props();
@@ -8,110 +8,411 @@
`${s.r}${s.sta ?? ''}${s.std ?? ''}${s.wtp ?? ''}`; `${s.r}${s.sta ?? ''}${s.std ?? ''}${s.wtp ?? ''}`;
</script> </script>
<div class="table-container"> <table class="departure-board">
<table class="departure-board"> <colgroup>
<thead> <col style="width:10%;" />
<tr> <!-- ID (Headcode) -->
<th colspan="4" aria-hidden="true"></th> <col style="width:17%;" />
<th scope="colgroup" colspan="2" class="upper-head"><abbr title="Arrival">Arr</abbr></th> <!-- ORIG (Origin) -->
<th scope="colgroup" colspan="2" class="upper-head"><abbr title="Departure">Dep</abbr></th> <col style="width:17%;" />
<th aria-hidden="true"></th> <!-- DEST (Destination) -->
</tr> <col style="width:9%;" />
<tr> <!-- PLT (Platform) -->
<th scope="col"><abbr title="Headcode">ID</abbr></th> <col style="width: 12%;" />
<th scope="col"><abbr title="Origin">Orig</abbr></th> <!-- STA -->
<th scope="col"><abbr title="Destination">Dest</abbr></th> <col style="width: 12%;" />
<th scope="col"><abbr title="Platform">Plt</abbr></th> <!-- ETA/ATA -->
<th scope="col"><abbr title="Scheduled">Sch</abbr></th> <col style="width: 12%;" />
<th scope="col"><abbr title="Actual/Expected">Act</abbr></th> <!-- STD -->
<th scope="col"><abbr title="Scheduled">Sch</abbr></th> <col style="width: 11%;" />
<th scope="col"><abbr title="Actual/Expected">Act</abbr></th> <!-- ETD/ATD -->
<th scope="col"><abbr title="+/- Time">+/-</abbr></th> </colgroup>
<thead>
<tr>
<th colspan="4" aria-hidden="true"></th>
<th scope="colgroup" colspan="2" class="upper-head"><abbr title="Arrival">Arr</abbr></th>
<th scope="colgroup" colspan="2" class="upper-head"><abbr title="Departure">Dep</abbr></th>
</tr>
<tr>
<th scope="col"><abbr title="Headcode">ID</abbr></th>
<th scope="col"><abbr title="Origin">Orig</abbr></th>
<th scope="col"><abbr title="Destination">Dest</abbr></th>
<th scope="col"><abbr title="Platform">Plt</abbr></th>
<th scope="col"><abbr title="Scheduled">Sch</abbr></th>
<th scope="col"><abbr title="Actual/Expected">Act</abbr></th>
<th scope="col"><abbr title="Scheduled">Sch</abbr></th>
<th scope="col"><abbr title="Actual/Expected">Act</abbr></th>
</tr>
</thead>
{#each services as service (getRowKey(service))}
<tbody>
<tr
class="service-row"
class:serviceCancelled={service.c}
class:servicePass={service.wtp}
class:serviceNonPassenger={!service.ip}
>
<td class="id-cell">{service.h}</td>
<td class="orig-cell"
><abbr title={service.og.n.toLocaleUpperCase()}>{service.og.t}</abbr></td
>
<td class="dest-cell"
><abbr title={service.dt.n.toLocaleUpperCase()}>{service.dt.t}</abbr></td
>
<td class="plt-cell" class:platSup={service.ps} class:platChange={service.pc}
>{service.p || '-'}</td
>
<!-- Handle different display for a passing train -->
{#if service.wtp}
<td class="pass-cell" colspan="2">Pass</td>
<td class="time-cell">{formatUkTime(service.wtp)}</td>
<!-- If cancelled, show '-', otherwise check for RT or show time -->
<td
class="time-cell {estClass(service.atp, service.etp)} {delayClassFromTimePair(
service.wtp,
service.atp || service.etp
)}"
>
<span>
{service.c
? '-'
: delayClassFromTimePair(service.wtp, service.atp || service.etp) === 'delay-rt'
? 'RT'
: formatUkTime(service.atp || service.etp)}
</span>
</td>
{:else}
<td class="time-cell">{formatUkTime(service.sta)}</td>
<!-- Arrival Actual/Expected -->
<td
class="time-cell {estClass(service.ata, service.eta)} {delayClassFromTimePair(
service.sta,
service.ata || service.eta
)}"
>
<span>
{service.c
? '-'
: delayClassFromTimePair(service.sta, service.ata || service.eta) === 'delay-rt'
? 'RT'
: formatUkTime(service.ata || service.eta)}
</span>
</td>
<td class="time-cell">{formatUkTime(service.std)}</td>
<!-- Departure Actual/Expected -->
<td
class="time-cell {estClass(service.atd, service.etd)} {delayClassFromTimePair(
service.std,
service.atd || service.etd
)}"
>
<span>
{service.c
? '-'
: delayClassFromTimePair(service.std, service.atd || service.etd) === 'delay-rt'
? 'RT'
: formatUkTime(service.atd || service.etd)}
</span>
</td>
{/if}
</tr> </tr>
</thead>
{#each services as service (getRowKey(service))} {#if service.o}
<tbody> <tr class="toc-coach-row">
<tr class="service-row" class:serviceCancelled={service.c}> <td colspan="8">
<td class="id-cell">{service.h}</td> {service.o}
<td class="orig-cell">{service.og.t}</td> </td>
<td class="dest-cell">{service.dt.t}</td> </tr>
<td class="plt-cell" class:platSup={service.ps} class:platChange={service.pc}>{service.p}</td> {/if}
{#if service.c && service.cr?.r}
<!-- Handle different display for a passing train --> <tr class="cancel-row">
{#if service.wtp} <td colspan="8">
<td colspan="2">Pass</td> {service.cr.r}
<td class="time-cell">{formatUkTime(service.wtp)}</td> {#if service.cr.l}
<td class="time-cell {estClass(service.atp, service.etp)}">{formatUkTime(service.atp || service.etp)}</td> {service.cr.n ? 'near' : 'at'}
{:else} {service.cr.l}
<td class="time-cell">{formatUkTime(service.sta)}</td> {/if}
<td class="time-cell {estClass(service.ata, service.eta)}">{formatUkTime(service.ata || service.eta)}</td> </td>
<td class="time-cell">{formatUkTime(service.std)}</td> </tr>
<td class="time-cell {estClass(service.atd, service.etd)}">{formatUkTime(service.atd || service.etd)}</td> {/if}
{/if} {#if service.dr?.r}
<tr class="delay-row">
{#if service} <td colspan="9">
{@const delay = calculateDelay(service)} {service.dr.r}
<td class="delay-cell delay-{delay.type}">{delay.val}</td> {#if service.dr.l}
{/if} {service.dr.n ? 'near' : 'at'}
</tr> {service.dr.l}
{/if}
{#if service.c && service.cr?.r} </td>
<tr> </tr>
<td colspan="9">{service.cr.r}</td> {/if}
</tr> </tbody>
{/if} {/each}
</tbody> </table>
{/each}
</table>
</div>
<style> <style>
.table-container { .departure-board {
width: 100%; width: 100%;
} margin: 5px auto;
.departure-board { border-collapse: collapse;
width: 100%; table-layout: fixed;
margin: 0 auto; }
font-family: 'URW Gothic', sans-serif;
font-variant-numeric: tabular-nums; .departure-board td {
} font-family: 'Inconsolata Variable', monospace;
.serviceCancelled { font-size: clamp(1rem, 0.475rem + 2.8vw, 1.35rem);
text-decoration: line-through; font-variant-ligatures: additional-ligatures;
} overflow: hidden;
.id-cell{ }
font-family:'Courier New', Courier, monospace;
text-align: center; thead,
} .cancel-row td,
.orig-cell, .dest-cell { .delay-row td {
color: var(--location-yellow); letter-spacing: -0.15ch;
} }
.orig-cell {
text-align: left; thead {
} position: sticky;
.dest-cell { top: 0;
text-align: right; z-index: 2;
} background: var(--color-bg-dark);
.plt-cell { }
text-align: center;
} abbr {
.platChange { text-decoration: none;
animation: 2s fast-pulse ease-in-out infinite; border-bottom: none;
} cursor: help;
.platSup { }
filter: opacity(0.5);
} tbody tr:first-child td {
.time-cell { border-top: 5px solid transparent;
text-align: center; }
}
.delay-cell { /* Row Logic */
text-align: center; .serviceCancelled {
} color: rgb(255, 131, 131);
.delay-late { }
color: var(--delay-orange);
} .servicePass td {
.delay-early { opacity: 0.75;
color: var(--early-blue); font-weight: 200;
} }
.serviceNonPassenger td {
opacity: 0.5;
font-weight: 290;
font-style: italic;
}
/* Special Row Styles */
.cancel-row td,
.delay-row td {
font-size: 0.88rem;
text-align: left;
}
.cancel-row td[colspan],
.delay-row td[colspan] {
padding-left: 0ch;
}
.cancel-row td {
color: rgb(255, 131, 131);
font-weight: 400;
}
.delay-row td {
color: var(--delay-orange);
font-style: italic;
}
@media (min-width: 375px) {
.cancel-row td,
.delay-row td {
font-size: 1.08rem;
}
}
@media (min-width: 420px) {
.cancel-row td,
.delay-row td {
font-size: 1.12rem;
}
}
@media (min-width: 550px) {
.cancel-row td,
.delay-row td {
font-size: 1.18rem;
}
}
@media (min-width: 620px) {
.cancel-row td,
.delay-row td {
font-size: 1.20rem;
}
}
.toc-coach-row td {
font-family: 'URW Gothic', sans-serif;
font-size: 0.7rem;
padding: 0;
color: rgb(187, 187, 255);
}
@media(min-width: 400px) {
.toc-coach-row td {
font-size: 0.8rem;
}
}
@media(min-width: 550px) {
.toc-coach-row td {
font-size: 0.85rem;
}
}
/* Column Specifics */
.id-cell {
text-align: left;
font-weight: 400;
font-stretch: 85%;
filter: brightness(0.75);
}
@media (min-width: 400px) {
.id-cell {
font-stretch: 90%;
}
}
.orig-cell,
.dest-cell {
font-stretch: 80%;
font-weight: 400;
}
.orig-cell {
text-align: left;
color: var(--location-yellow);
}
.dest-cell {
text-align: right;
color: var(--location-yellow);
}
@media (min-width: 350px) {
.orig-cell,
.dest-cell {
font-stretch: 85%;
}
@media (min-width: 400px) {
.orig-cell,
.dest-cell {
font-stretch: 90%;
}
}
@media (min-width: 490px) {
.orig-cell,
.dest-cell {
font-stretch: 95%;
}
}
@media (min-width: 520px) {
.orig-cell,
.dest-cell {
font-stretch: 100%;
}
.orig-cell {
text-align: right;
padding-right: 7px;
}
.dest-cell {
text-align: left;
padding-left: 7px;
}
}
@media (min-width: 600px) {
.orig-cell,
.dest-cell {
letter-spacing: 0.05ch;
}
}
}
.plt-cell {
text-align: center;
font-weight: 410;
font-stretch: 100%;
}
@media (min-width: 525px) {
.plt-cell {
font-stretch: 110%;
}
}
.plt-cell.platSup {
font-weight: 200;
opacity: 0.3;
}
.plt-cell.platChange {
animation: fast-pulse 2s ease-out infinite;
}
.service-row.serviceCancelled .plt-cell {
text-decoration: line-through;
}
.pass-cell {
text-align: center;
font-stretch: 100%;
}
/* Colour orig and dest values when cancelled */
.service-row.serviceCancelled .orig-cell,
.service-row.serviceCancelled .dest-cell {
color: rgb(255, 131, 131);
}
.time-cell {
text-align: center;
font-stretch: 72%;
}
@media (min-width: 350px) {
.time-cell {
font-stretch: 77%;
}
}
@media (min-width: 400px) {
.time-cell {
font-stretch: 82%;
}
}
@media (min-width: 525px) {
.time-cell {
font-stretch: 90%;
}
}
@media (min-width: 600px) {
.time-cell {
font-stretch: 100%;
}
}
/* RT Logic */
.time-cell.delay-rt span {
display: none;
}
.time-cell.delay-rt::after {
content: 'RT';
}
.time-cell.delay-early {
color: var(--early-blue);
}
.time-cell.delay-late {
color: var(--delay-orange);
}
/* Time Types */
.est {
font-style: italic;
opacity: 0.75;
font-weight: 200;
}
.act {
font-weight: 600;
}
</style> </style>

View File

@@ -41,7 +41,7 @@
<style> <style>
.alert-card { .alert-card {
margin: 1rem 0; margin: 0;
border-radius: 8px; border-radius: 8px;
background: transparent; background: transparent;
position: relative; position: relative;
@@ -49,6 +49,11 @@
margin-bottom: 0; margin-bottom: 0;
width: 95%; width: 95%;
max-width: 750px; max-width: 750px;
-webkit-tap-highlight-color: transparent;
}
.alert-card:active {
filter: brightness(1.2);
} }
.trigger { .trigger {
@@ -56,7 +61,7 @@
display: flex; display: flex;
border-radius: 8px; border-radius: 8px;
align-items: center; align-items: center;
padding: 0.4rem 1rem; padding: 0.1rem 1.05rem;
background: var(--alert-orange); background: var(--alert-orange);
color: white; color: white;
border: none; border: none;
@@ -64,13 +69,13 @@
text-align: left; text-align: left;
position: relative; position: relative;
z-index: 2; z-index: 2;
height: 46px; height: 40px;
transition: all 0.65s 0.2s; transition: all 0.65s 0.2s;
} }
.trigger.active { .trigger.active {
border-radius: 8px 8px 0 0; border-radius: 8px 8px 0 0;
transition: all 0.1s 0s; transition: all 0.01s 0s;
} }
.warning-icon { .warning-icon {
@@ -105,7 +110,7 @@
.content { .content {
padding: 1rem; padding: 1rem;
position: absolute; position: absolute;
top: 46px; top: 40px;
border-radius: 0 0 8px 8px; border-radius: 0 0 8px 8px;
left: 0; left: 0;
right: 0; right: 0;

View File

@@ -129,7 +129,41 @@
font-style: normal; font-style: normal;
font-display: swap; font-display: swap;
} }
/* Fira Code - Variable with fallback */
@font-face {
font-family: 'Fira Code';
src: url('/type/fira-code/FiraCode-VF.woff2') format('woff2-variations');
font-weight: 300 700;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Fira Code';
src: url('/type/fira-code/FiraCode-Regular.woff2') format('woff2');
font-weight: 400;
font-style: normal;
font-display: swap;
}
/* Inconsolata Variable */
@font-face {
font-family: 'Inconsolata Variable';
font-style: normal;
font-display: swap;
font-weight: 200 900;
font-stretch: 50% 200%;
src: url(/type/inconsolata/latin-wdth-normal.woff2) format('woff2-variations');
unicode-range:
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
:root { :root {
/* Fixed Heights */
--header-height: 80px;
--nav-height: 60px;
/* Brand Colours */ /* Brand Colours */
--color-brand: #4fd1d1; --color-brand: #4fd1d1;
--color-accent: #3c6f79; --color-accent: #3c6f79;
@@ -159,7 +193,7 @@
opacity: 1; opacity: 1;
} }
50% { 50% {
opacity: 0.3; opacity: 0.5;
} }
} }

View File

@@ -1,6 +1,6 @@
import type { ApiTrainsTrainDetails } from '@owlboard/owlboard-ts'; import type { ApiTrainsTrainDetails } from '@owlboard/owlboard-ts';
export const estClass = (act: any, est: any) => (!act && est ? 'est' : 'act'); export const estClass = (act: any, est: any) => (act ? 'act' : 'est');
/** /**
* Converts ISO/JSON time to UK-formatted HH:MM string, with optional (default off) seconds * Converts ISO/JSON time to UK-formatted HH:MM string, with optional (default off) seconds
@@ -10,10 +10,10 @@ export function formatUkTime(
dateStr: string | Date | undefined, dateStr: string | Date | undefined,
includeSeconds: boolean = false includeSeconds: boolean = false
): string { ): string {
if (!dateStr) return '--:--'; if (!dateStr) return '-';
const date = typeof dateStr === 'string' ? new Date(dateStr) : dateStr; const date = typeof dateStr === 'string' ? new Date(dateStr) : dateStr;
if (isNaN(date.getTime())) return '--:--'; if (isNaN(date.getTime())) return '-';
return date.toLocaleTimeString('en-GB', { return date.toLocaleTimeString('en-GB', {
hour: '2-digit', hour: '2-digit',
@@ -56,15 +56,21 @@ export function formatUkDateTime(
* Specific type that can handle the TrainDetails.ServiceLocation and the ApiStationsBoard.BoardService types for delay calculation * Specific type that can handle the TrainDetails.ServiceLocation and the ApiStationsBoard.BoardService types for delay calculation
*/ */
interface DelayInput { interface DelayInput {
// Board types // Board types
sta?: string | null; std?: string | null; sta?: string | null;
eta?: string | null; etd?: string | null; std?: string | null;
ata?: string | null; atd?: string | null; eta?: string | null;
etd?: string | null;
ata?: string | null;
atd?: string | null;
// Journey types // Journey types
pta?: string | null; ptd?: string | null; pta?: string | null;
wta?: string | null; wtd?: string | null; ptd?: string | null;
atp?: string | null; wtp?: string | null; wta?: string | null;
wtd?: string | null;
atp?: string | null;
wtp?: string | null;
etp?: string | null; etp?: string | null;
} }
@@ -79,13 +85,13 @@ export function calculateDelay(loc: DelayInput): {
type: string; type: string;
} { } {
const pairs = [ const pairs = [
// Departure check (Board: atd/etd vs std | Journey: atd vs ptd/wtd) // Departure check (Board: atd/etd vs std | Journey: atd vs ptd/wtd)
{ actual: loc.atd || loc.etd, sched: loc.std || loc.ptd || loc.wtd }, { actual: loc.atd || loc.etd, sched: loc.std || loc.ptd || loc.wtd },
// Arrival check (Board: ata/eta vs sta | Journey: ata vs pta/wta) // Arrival check (Board: ata/eta vs sta | Journey: ata vs pta/wta)
{ actual: loc.ata || loc.eta, sched: loc.sta || loc.pta || loc.wta }, { actual: loc.ata || loc.eta, sched: loc.sta || loc.pta || loc.wta },
// Passing check // Passing check
{ actual: loc.atp || loc.etp, sched: loc.wtp } { actual: loc.atp || loc.etp, sched: loc.wtp }
]; ];
const match = pairs.find((p) => p.actual && p.sched); const match = pairs.find((p) => p.actual && p.sched);
@@ -102,3 +108,27 @@ export function calculateDelay(loc: DelayInput): {
return { val: `${absDiff}E`, type: 'early' }; return { val: `${absDiff}E`, type: 'early' };
} }
} }
/**
* Accepts a pair of times (string or Date) and outputs a delay class 'delay-early', 'delay-late' or 'delay-rt'
* @param sched Scheduled Time (string, Date)
* @param act Actual Time (string, Date)
*/
export function delayClassFromTimePair(sched: any, act: any): string {
if (!sched || !act) return '';
const s = new Date(sched).getTime();
const a = new Date(act).getTime();
if (isNaN(s) || isNaN(a)) return '';
const diff = a - s;
const oneMinute = 60000;
// on-time if within one minute
if (Math.abs(diff) < oneMinute) {
return 'delay-rt';
}
return diff > 0 ? 'delay-late' : 'delay-early';
}

View File

@@ -29,7 +29,7 @@
</div> </div>
{/if} {/if}
{#if $page.error?.owlCode === 'NETWORK_DISCONNECTED'} {#if page.error?.owlCode === 'NETWORK_DISCONNECTED'}
<Button onclick={() => window.location.reload()} color={'accent'}>Retry</Button> <Button onclick={() => window.location.reload()} color={'accent'}>Retry</Button>
{:else} {:else}
<Button href={'/'} color={'accent'}>Return to Home</Button> <Button href={'/'} color={'accent'}>Return to Home</Button>

View File

@@ -2,9 +2,9 @@
import { page } from '$app/state'; import { page } from '$app/state';
import { slide, fade } from 'svelte/transition'; import { slide, fade } from 'svelte/transition';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { browser } from '$app/environment';
import { navigating } from '$app/state'; import { navigating } from '$app/state';
import { LOCATIONS } from '$lib/locations-object.svelte'; import { LOCATIONS } from '$lib/locations-object.svelte';
import { nearestStationsState } from '$lib/geohash.svelte';
import Loading from '$lib/components/ui/Loading.svelte'; import Loading from '$lib/components/ui/Loading.svelte';
import TimezoneWarning from '$lib/components/ui/TimezoneWarning.svelte'; import TimezoneWarning from '$lib/components/ui/TimezoneWarning.svelte';
@@ -17,7 +17,19 @@
import { IconHome, IconDialpad, IconSettings, IconHelp, IconDots } from '@tabler/icons-svelte'; import { IconHome, IconDialpad, IconSettings, IconHelp, IconDots } from '@tabler/icons-svelte';
onMount(() => LOCATIONS.init()); onMount(async () => {
LOCATIONS.init();
if (browser && 'serviceWorker' in navigator) {
try {
const registration = await navigator.serviceWorker.register('/service-worker.js', {
type: 'module',
});
console.info('OwlBoard Service Worker registered', registration.scope);
} catch (error) {
console.error('Service Worker installation failed: ', error)
}
}
});
let { children } = $props(); let { children } = $props();
@@ -147,14 +159,14 @@
<h1 class="viewport-guard-title">Narrow Gauge Detected</h1> <h1 class="viewport-guard-title">Narrow Gauge Detected</h1>
<p> <p>
Just as trains need the right track width, our data needs a bit more room to stay on the rails. Just as trains need the right track width, our data needs a bit more room to stay on the rails.
Please expand your view to at least 300px to view the app. Please expand your view to at least 320px to view the app.
</p> </p>
</div> </div>
<style> <style>
header { header {
top: 0; top: 0;
height: 80px; height: var(--header-height);
box-shadow: var(--shadow-std); box-shadow: var(--shadow-std);
} }
.logo-link { .logo-link {
@@ -201,13 +213,12 @@
min-height: 100dvh; min-height: 100dvh;
box-sizing: border-box; box-sizing: border-box;
background-color: var(--color-bg-dark); background-color: var(--color-bg-dark);
background-image: radial-gradient(var(--color-bg-dark), var(--color-bg-light));
} }
nav { nav {
display: flex; display: flex;
bottom: 0; bottom: 0;
height: 60px; height: var(--nav-height);
box-shadow: var(--shadow-up); box-shadow: var(--shadow-up);
} }
@@ -320,7 +331,7 @@
display: none; display: none;
} }
@media (max-width: 299px) { @media (max-width: 319px) {
.viewport-guard { .viewport-guard {
display: block; display: block;
position: fixed; position: fixed;

View File

@@ -36,26 +36,29 @@
</script> </script>
<section class="board-wrapper"> <section class="board-wrapper">
{#if data.boardData.data.m?.length}
<StationAlertCard messages={data.boardData.data.m} />
{/if}
<div class="time-data"> <div class="time-data">
<span class="time-loaded">Updated: {formatUkDateTime(data.boardData.producedAt, true)}</span> <span class="time-loaded">Updated: {formatUkDateTime(data.boardData.producedAt, true)}</span>
<span class="time-now">{formatUkTime(now, true)}</span> <span class="time-now">{formatUkTime(now, true)}</span>
</div> </div>
{#if data.boardData.data.s?.length} {#if data.boardData.data.m?.length}
<StaffServicesTable services={data.boardData.data.s} /> <StationAlertCard messages={data.boardData.data.m} />
{/if}
{#if data.boardData.data.s?.length}
<div class="service-list-wrapper">
<StaffServicesTable services={data.boardData.data.s} />
</div>
{/if} {/if}
<pre class="json-dump">{JSON.stringify(data.boardData.data.s, null, 2)}</pre>
</section> </section>
<style> <style>
.board-wrapper { .board-wrapper {
display: flex; display: flex;
height: calc(100dvh - var(--nav-height) - var(--header-height));
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
width: 100%; width: 100%;
margin: 0 auto; margin: 0 auto;
overflow: hidden;
gap: 0; gap: 0;
} }
@@ -82,21 +85,13 @@
font-weight: 600; font-weight: 600;
font-size: 1rem; font-size: 1rem;
} }
pre {
max-width: 100%; .service-list-wrapper {
white-space: pre-wrap; flex: 1;
word-wrap: break-word; overflow-y: auto;
box-sizing: border-box; height: calc(100dvh - 60px);
overflow-x: auto; width: 97%;
} max-width: 700px;
.json-dump { margin-bottom: 5px;
background: #222;
color: #0f0;
padding: 1rem;
border-radius: 4px;
font-size: 0.9rem;
max-height: 500px;
width: 95%;
margin: 1rem auto;
} }
</style> </style>

76
src/service-worker.ts Normal file
View File

@@ -0,0 +1,76 @@
/// <reference types="@sveltejs/kit" />
/// <reference lib="webworker" />
import type { ApiEnvelope } from '@owlboard/api-schema-types';
import { build, files, version } from '$service-worker';
const sw = self as unknown as ServiceWorkerGlobalScope;
const CACHE_NAME = `owlboard-cache-${version}`;
const ASSETS = [...build, ...files, '/'];
sw.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS))
);
});
sw.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((keys) => {
return Promise.all(
keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))
);
})
);
});
sw.addEventListener('fetch', (event) => {
const { request } = event;
if (request.method !== 'GET') return;
const url = new URL(request.url);
// 1. Static Assets (Cache-First)
if (ASSETS.includes(url.pathname) || url.pathname.startsWith('/_app/')) {
event.respondWith(
caches.match(request).then((res) => res || fetch(request))
);
return;
}
// 2. Offline API Fallback (Network-First)
if (url.pathname.startsWith('/api') || url.hostname.includes('api')) {
event.respondWith(
fetch(request).catch(() => {
const errorObject: ApiEnvelope.Envelope = {
e: {
code: "NETWORK_DISCONNECTED",
msg: "Cannot connect to the OwlBoard server"
},
t: Math.floor(Date.now() / 1000)
};
return new Response(
JSON.stringify(errorObject),
{
status: 503,
headers: { 'Content-Type': 'application/json' }
}
);
})
);
return;
}
// 3. Navigation Fallback (The Offline 404 Catch-All)
// This catches top-level page navigations and hard refreshes
if (request.mode === 'navigate' || request.headers.get('accept')?.includes('text/html')) {
event.respondWith(
fetch(request).catch(() => {
// The network request failed entirely (offline).
// Serve the cached root shell so SvelteKit can boot.
return caches.match('/') as Promise<Response>;
})
);
return;
}
});

Binary file not shown.