mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-13 02:53:45 +00:00
37 lines
724 B
Svelte
37 lines
724 B
Svelte
<script lang="ts">
|
|
import { onMount } from 'svelte';
|
|
|
|
export let pokedexNumber: string | number;
|
|
export let form: string | undefined;
|
|
|
|
let imagePath = null as string | null;
|
|
|
|
async function fetchImagePath() {
|
|
try {
|
|
let url = `/api/sprite?pokedexNumber=${pokedexNumber}`;
|
|
if (form) {
|
|
url += `&form=${form}`;
|
|
}
|
|
|
|
const response = await fetch(url);
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to fetch image path');
|
|
}
|
|
const data = await response.json();
|
|
|
|
imagePath = `./sprites/regular/${data.spriteFileName}`;
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
onMount(fetchImagePath);
|
|
</script>
|
|
|
|
{#if imagePath}
|
|
<img src={imagePath} alt="sprite" />
|
|
{:else}
|
|
<p>Loading...</p>
|
|
{/if}
|