Add PIS Logic
This commit is contained in:
15
package-lock.json
generated
15
package-lock.json
generated
@@ -8,13 +8,12 @@
|
||||
"name": "web-pwa",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"@owlboard/owlboard-ts": "^3.0.0",
|
||||
"@tabler/icons-svelte": "^3.40.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^2.0.2",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@owlboard/owlboard-ts": "^3.0.0",
|
||||
"@owlboard/owlboard-ts": "^3.0.0-dev.20260319T2004",
|
||||
"@playwright/test": "^1.58.1",
|
||||
"@sveltejs/adapter-static": "^3.0.10",
|
||||
"@sveltejs/kit": "^2.50.2",
|
||||
@@ -788,9 +787,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@owlboard/owlboard-ts": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fowlboard-ts/-/3.0.0/owlboard-ts-3.0.0.tgz",
|
||||
"integrity": "sha512-ycmBQ8JEwSFDLeRg7pb+g+umljHQ/vqrZ+BIs7qmwZyOVyuCjzny6keiHdhMALiNBDD9yU9DzJpqxry78rCIYg==",
|
||||
"version": "3.0.0-dev.20260319T2004",
|
||||
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fowlboard-ts/-/3.0.0-dev.20260319T2004/owlboard-ts-3.0.0-dev.20260319t2004.tgz",
|
||||
"integrity": "sha512-pphq1/l/8eOH4C0O7ocwBOUzt0HkCWGUlhy1itzKnQbmog7oPUEdyaxzS4Evw8onLsxZwkyqsLAyK7okYi+4XA==",
|
||||
"dev": true,
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
@@ -2471,9 +2470,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/flatted": {
|
||||
"version": "3.4.1",
|
||||
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.1.tgz",
|
||||
"integrity": "sha512-IxfVbRFVlV8V/yRaGzk0UVIcsKKHMSfYw66T/u4nTwlWteQePsxe//LjudR1AMX4tZW3WFCh3Zqa/sjlqpbURQ==",
|
||||
"version": "3.4.2",
|
||||
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.2.tgz",
|
||||
"integrity": "sha512-PjDse7RzhcPkIJwy5t7KPWQSZ9cAbzQXcafsetQoD7sOJRQlGikNbx7yZp2OotDnJyrDcbyRq3Ttb18iYOqkxA==",
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^2.0.2",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@owlboard/owlboard-ts": "^3.0.0",
|
||||
"@owlboard/owlboard-ts": "^3.0.0-dev.20260319T2004",
|
||||
"@playwright/test": "^1.58.1",
|
||||
"@sveltejs/adapter-static": "^3.0.10",
|
||||
"@sveltejs/kit": "^2.50.2",
|
||||
@@ -42,7 +42,6 @@
|
||||
"vitest-browser-svelte": "^2.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tabler/icons-svelte": "^3.40.0",
|
||||
"@owlboard/owlboard-ts": "^3.0.0"
|
||||
"@tabler/icons-svelte": "^3.40.0"
|
||||
}
|
||||
}
|
||||
|
||||
21
src/lib/owlClient.ts
Normal file
21
src/lib/owlClient.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { OwlBoardClient, ValidationError, ApiError } from "@owlboard/owlboard-ts";
|
||||
import { browser, dev } from "$app/environment";
|
||||
|
||||
// Import the runes containing the API Key config Here...
|
||||
|
||||
const baseUrl: string = browser ? window.location.origin : '';
|
||||
|
||||
const getBaseUrl = () => {
|
||||
if (!browser) return '';
|
||||
|
||||
if (dev) return 'https://test.owlboard.info';
|
||||
|
||||
return window.location.origin;
|
||||
}
|
||||
|
||||
export const OwlClient = new OwlBoardClient(
|
||||
getBaseUrl(),
|
||||
// API Key Here when ready!!!
|
||||
)
|
||||
|
||||
export { ValidationError, ApiError };
|
||||
@@ -3,13 +3,28 @@
|
||||
import PisCode from '$lib/components/ui/cards/pis/PisCode.svelte';
|
||||
import Button from '$lib/components/ui/Button.svelte';
|
||||
import type { PisObjects } from '@owlboard/api-schema-types';
|
||||
import { OwlClient, ApiError, ValidationError } from '$lib/owlClient';
|
||||
|
||||
let results = $state<PisObjects[]>([]);
|
||||
let resultsLoaded = $state<boolean>(false);
|
||||
let errorState = $state<{status: number, message: message} | null>(null);
|
||||
|
||||
function handleStartEndSearch(start: string, end: string) {
|
||||
async function handleStartEndSearch(start: string, end: string): Promise<void> {
|
||||
console.log(`PIS Search: ${start}-${end}`);
|
||||
// Fetch API Results Here
|
||||
errorState = null;
|
||||
|
||||
try {
|
||||
results = await OwlClient.pis.getByStartEndCrs(start, end);
|
||||
} catch (e) {
|
||||
if (e instanceof ValidationError) {
|
||||
errorState = { status: 400, message: e.message };
|
||||
} else if (e instanceof ApiError) {
|
||||
errorState = { status: 500, message: e.message };
|
||||
} else {
|
||||
errorState = { status: 0, message: `Unknown Error: ${e.message}` };
|
||||
}
|
||||
}
|
||||
|
||||
resultsLoaded = true;
|
||||
}
|
||||
|
||||
@@ -33,11 +48,15 @@
|
||||
</div>
|
||||
{:else}
|
||||
<div class="result-container">
|
||||
{#if errorState}
|
||||
<span class="errCode">{errorState.status}</span>
|
||||
<span class="errMsg">{errorState.message}</span>
|
||||
{:else}
|
||||
{#if !results.length}
|
||||
<p class="no-results">No results found</p>
|
||||
{:else}
|
||||
<p class="no-results">Unable to load results</p>
|
||||
{/if}
|
||||
<p class="no-results">Results Loaded - Display logic not present</p>
|
||||
{/if}{/if}
|
||||
<Button onclick={clearResults}>Reset</Button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user