<script>
import Entry from './Entry.svelte';
const pokemon = 898;
let number = Math.floor(Math.random() * pokemon + 1);
let fetchedNumber;
const favorites = {};
async function fetchData(n = 1) {
try {
const res = await fetch(`https://pokeapi.co/api/v2/pokemon/${n}`);
const data = await res.json();
fetchedNumber = number;
return data;
}
catch(error) {
throw new Error(error)
}
}
function handleSubmit() {
if(fetchedNumber === number) return;
promise = fetchData(number);
}
function handleFavorite({detail}) {
favorites[fetchedNumber] = detail;
}
let promise;
</script>
<style>
:global(*) {
padding: 0;
margin: 0;