Replace result-island

This commit is contained in:
Fred Boniface 2024-07-07 21:23:15 +01:00
parent 512c77e81c
commit 284dedbb3f
2 changed files with 27 additions and 39 deletions

View File

@ -1,31 +0,0 @@
<script lang="ts">
import Island from "$lib/islands/island.svelte";
interface resultObj {
results: boolean;
title: string;
resultLines: string[];
}
export let resultObject: resultObj = {
results: true,
title: "",
resultLines: [],
};
let variables = {
title: resultObject.title,
};
</script>
<Island {variables}>
{#each resultObject.resultLines as line}
<p>{line}</p>
{/each}
</Island>
<style>
p {
color: var(--island-text-color);
}
</style>

View File

@ -1,19 +1,33 @@
<script> <script lang="ts">
import { onMount } from "svelte"; import { onMount } from "svelte";
import Header from "$lib/navigation/header.svelte"; import Header from "$lib/navigation/header.svelte";
import Nav from "$lib/navigation/nav.svelte"; import Nav from "$lib/navigation/nav.svelte";
import Loading from "$lib/navigation/loading.svelte"; import Loading from "$lib/navigation/loading.svelte";
import ResultIsland from "$lib/islands/result-island.svelte"; import Card from "$lib/cards/Card.svelte";
import { getApiUrl } from "$lib/scripts/upstream"; import { CardConfig } from "$lib/cards/Card.types";
import { apiGet } from "$lib/scripts/apiFetch";
interface ApiResponse {
results: boolean;
title: string;
resultLines: string[];
}
const title = "Reason Codes"; const title = "Reason Codes";
let isLoading = false; let isLoading = false;
let inputValue = ""; let inputValue = "";
let resultObject = { let resultObject: ApiResponse = {
results: false, results: false,
title: "", title: "",
resultLines: [], resultLines: [],
}; };
let config: CardConfig = {
title: "",
showHelp: false,
showRefresh: false,
helpText: "",
onRefresh: () => {},
refreshing: false,
}
function load() { function load() {
isLoading = true; isLoading = true;
@ -26,9 +40,9 @@
async function getData() { async function getData() {
if (inputValue) { if (inputValue) {
const url = `${getApiUrl()}/api/v2/ref/reasonCode/${inputValue}`; const apiPath = `/api/v2/ref/reasonCode/${inputValue}`;
const res = await fetch(url); const res = await apiGet(apiPath)
return await res.json(); return res
} else { } else {
return []; return [];
} }
@ -47,6 +61,7 @@
}; };
} }
resultObject.resultLines = resultLines; resultObject.resultLines = resultLines;
config.title = resultObject.title;
resultObject.results = true; resultObject.results = true;
} }
@ -79,7 +94,11 @@
{/if} {/if}
{#if resultObject.results} {#if resultObject.results}
<ResultIsland {resultObject} /> <Card {config}>
{#each resultObject.resultLines as line}
<p>{line}</p>
{/each}
</Card>
{/if} {/if}
<Nav /> <Nav />