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",
|
"name": "web-pwa",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@owlboard/owlboard-ts": "^3.0.0",
|
|
||||||
"@tabler/icons-svelte": "^3.40.0"
|
"@tabler/icons-svelte": "^3.40.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/compat": "^2.0.2",
|
"@eslint/compat": "^2.0.2",
|
||||||
"@eslint/js": "^9.39.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",
|
"@playwright/test": "^1.58.1",
|
||||||
"@sveltejs/adapter-static": "^3.0.10",
|
"@sveltejs/adapter-static": "^3.0.10",
|
||||||
"@sveltejs/kit": "^2.50.2",
|
"@sveltejs/kit": "^2.50.2",
|
||||||
@@ -788,9 +787,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@owlboard/owlboard-ts": {
|
"node_modules/@owlboard/owlboard-ts": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0-dev.20260319T2004",
|
||||||
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fowlboard-ts/-/3.0.0/owlboard-ts-3.0.0.tgz",
|
"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-ycmBQ8JEwSFDLeRg7pb+g+umljHQ/vqrZ+BIs7qmwZyOVyuCjzny6keiHdhMALiNBDD9yU9DzJpqxry78rCIYg==",
|
"integrity": "sha512-pphq1/l/8eOH4C0O7ocwBOUzt0HkCWGUlhy1itzKnQbmog7oPUEdyaxzS4Evw8onLsxZwkyqsLAyK7okYi+4XA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -2471,9 +2470,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/flatted": {
|
"node_modules/flatted": {
|
||||||
"version": "3.4.1",
|
"version": "3.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.2.tgz",
|
||||||
"integrity": "sha512-IxfVbRFVlV8V/yRaGzk0UVIcsKKHMSfYw66T/u4nTwlWteQePsxe//LjudR1AMX4tZW3WFCh3Zqa/sjlqpbURQ==",
|
"integrity": "sha512-PjDse7RzhcPkIJwy5t7KPWQSZ9cAbzQXcafsetQoD7sOJRQlGikNbx7yZp2OotDnJyrDcbyRq3Ttb18iYOqkxA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/compat": "^2.0.2",
|
"@eslint/compat": "^2.0.2",
|
||||||
"@eslint/js": "^9.39.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",
|
"@playwright/test": "^1.58.1",
|
||||||
"@sveltejs/adapter-static": "^3.0.10",
|
"@sveltejs/adapter-static": "^3.0.10",
|
||||||
"@sveltejs/kit": "^2.50.2",
|
"@sveltejs/kit": "^2.50.2",
|
||||||
@@ -42,7 +42,6 @@
|
|||||||
"vitest-browser-svelte": "^2.0.2"
|
"vitest-browser-svelte": "^2.0.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tabler/icons-svelte": "^3.40.0",
|
"@tabler/icons-svelte": "^3.40.0"
|
||||||
"@owlboard/owlboard-ts": "^3.0.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 PisCode from '$lib/components/ui/cards/pis/PisCode.svelte';
|
||||||
import Button from '$lib/components/ui/Button.svelte';
|
import Button from '$lib/components/ui/Button.svelte';
|
||||||
import type { PisObjects } from '@owlboard/api-schema-types';
|
import type { PisObjects } from '@owlboard/api-schema-types';
|
||||||
|
import { OwlClient, ApiError, ValidationError } from '$lib/owlClient';
|
||||||
|
|
||||||
let results = $state<PisObjects[]>([]);
|
let results = $state<PisObjects[]>([]);
|
||||||
let resultsLoaded = $state<boolean>(false);
|
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}`);
|
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;
|
resultsLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,11 +48,15 @@
|
|||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="result-container">
|
<div class="result-container">
|
||||||
|
{#if errorState}
|
||||||
|
<span class="errCode">{errorState.status}</span>
|
||||||
|
<span class="errMsg">{errorState.message}</span>
|
||||||
|
{:else}
|
||||||
{#if !results.length}
|
{#if !results.length}
|
||||||
<p class="no-results">No results found</p>
|
<p class="no-results">No results found</p>
|
||||||
{:else}
|
{:else}
|
||||||
<p class="no-results">Unable to load results</p>
|
<p class="no-results">Results Loaded - Display logic not present</p>
|
||||||
{/if}
|
{/if}{/if}
|
||||||
<Button onclick={clearResults}>Reset</Button>
|
<Button onclick={clearResults}>Reset</Button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user