Skip to content

Commit

Permalink
add pokedex project to site
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukalus committed Oct 31, 2024
1 parent 3d87270 commit 8a800b6
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
43 changes: 43 additions & 0 deletions frontend/src/components/projects/pokedex/Pokedex.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script lang="ts">
import { P } from "flowbite-svelte";
import Pokeimage from "./Pokeimage.svelte"
let searchname: string;
let pokelistpromise = catchpokemon("https://pokeapi.co/api/v2/pokemon/?offset=0&limit=151");
async function catchpokemon(api_link: string){
const res = await fetch(api_link);
const data = await res.json();
if(res.ok){
return(data);
}
else{
throw new Error(data);
}
}
</script>

<main>
<div class="centerpokedex pokedex">
<P><h1 class="container">Pokedex</h1></P>
<input class="container searchbar" bind:value={searchname} placeholder="Type in your pokemon">
{#await pokelistpromise}
<p>... loading</p>
{:then pokelist}
{#each pokelist.results as pokemon}
{#if pokemon.name.includes(searchname)}
<Pokeimage link="{pokemon.url}"></Pokeimage>
{/if}
{/each}
{:catch error}
<p>error</p>
{/await}
</div>



</main>


79 changes: 79 additions & 0 deletions frontend/src/components/projects/pokedex/Pokeimage.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<script>
import { Accordion, AccordionItem, P } from "flowbite-svelte";
export let link;
let pokemonpromise = current_pokemon(link);
async function current_pokemon(api_link){
const res = await fetch(api_link);
const pokemon_data = await res.json();
if(res.ok){
return(pokemon_data);
}
else{
throw new Error(pokemon_data);
}
}
</script>



{#await pokemonpromise }
..loading
{:then pokemondetails}


<!-- Pokemon Characteristics -->
<div class="centercharacter container">
<P class="container">No.{pokemondetails.id} {pokemondetails.name}</P>
{#each pokemondetails.types as types }
<P class="container">{types.type.name}</P>
{/each}
<div class="img pokeimg">
<img src="{pokemondetails.sprites.front_default}" alt="error">
</div>
<P class="container">weight: {pokemondetails.weight} lbs</P>
<P class="container">height: {pokemondetails.height} inches</P>
</div>
<!-- Stats and Attacks -->
<Accordion >
<AccordionItem>
<span slot="header">Stats</span>
{#each pokemondetails.stats as stats }
<P>{stats.stat.name}:</P>
<P>{stats.base_stat}:</P>
{/each}
</AccordionItem>
<AccordionItem>
<span slot="header">Attacks</span>
{#each pokemondetails.moves as moves }
<P>{moves.move.name}</P>
{/each}
</AccordionItem>
</Accordion>
{/await}

<style>
.pokeimg{
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
background-color: white;
width: 96px;
border-radius: 50px;
margin: 16px;
border: 4px rgb(136, 136, 136);
}
.pokeimg:hover{
-webkit-transform: scaleX(1);
transform: scaleX(1);
background-color: white;
width: 96px;
border-radius: 50px;
margin: 16px;
}
</style>
5 changes: 5 additions & 0 deletions frontend/src/routes/projects/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import { P } from "flowbite-svelte";
</script>

<P ><a href="/projects/pokedex">Pokedex</a></P>
5 changes: 5 additions & 0 deletions frontend/src/routes/projects/pokedex/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import Pokedex from "src/components/projects/pokedex/Pokedex.svelte";
</script>

<Pokedex/>

0 comments on commit 8a800b6

Please sign in to comment.