mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-13 02:53:45 +00:00
feat(#11): Add sprite component
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<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}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user