File tree 6 files changed +75
-4
lines changed
6 files changed +75
-4
lines changed Original file line number Diff line number Diff line change
1
+ <script lang =" ts" >
2
+ import { onMount } from ' svelte' ;
3
+ import { fetchPokemon , type Pokemon } from ' ./pokeClient' ;
4
+ export let id: string ;
5
+ let pokemonFetch: Promise <Pokemon >;
6
+ onMount (() => {
7
+ pokemonFetch = fetchPokemon (id );
8
+ });
9
+ </script >
10
+
11
+ <div class =" flex flex-col items-center" >
12
+ {#if pokemonFetch !== undefined }
13
+ {#await pokemonFetch }
14
+ <h2 >Loading...</h2 >
15
+ {:then pokemon }
16
+ <img height ={200 } width ={200 } src ={pokemon .sprites .front_default } alt ={pokemon .name } />
17
+ <div >
18
+ Name: {pokemon .name .charAt (0 ).toUpperCase () + pokemon .name .slice (1 )}
19
+ </div >
20
+ <div >Weight: {pokemon .weight }</div >
21
+ {/await }
22
+ {/if }
23
+ </div >
Original file line number Diff line number Diff line change
1
+ <script lang =" ts" >
2
+ let id = (Math .random () * 1000 ).toFixed ();
3
+ </script >
4
+
5
+ <a href ={` /pokemon/${id } ` }> Random Pokemon </a >
Original file line number Diff line number Diff line change 1
1
<script >
2
+ import RandomPokemonLink from ' ../$lib/client/randomPokemonLink.svelte' ;
2
3
import ' ../app.css' ;
3
4
</script >
4
5
5
- <slot />
6
+ <div class =" flex min-h-screen w-full flex-col items-center p-16 text-white bg-black" >
7
+ <RandomPokemonLink />
8
+
9
+ <div class =" p-8" ><slot /></div >
10
+ </div >
Original file line number Diff line number Diff line change 1
- <h1 class =" text-3xl font-bold underline" >Hello world!</h1 >
2
-
3
- <p >Visit <a href =" https://kit.svelte.dev" >kit.svelte.dev</a > to read the documentation</p >
Original file line number Diff line number Diff line change
1
+ import { createPost , readPosts } from '../../../$lib/server/sbClient' ;
2
+ import type { Actions , PageServerLoad } from './$types' ;
3
+
4
+ export const load = ( async ( { params } ) => {
5
+ return { id : params . id , posts : await readPosts ( params . id ) . then ( ( data ) => data . data ?? [ ] ) } ;
6
+ } ) satisfies PageServerLoad ;
7
+
8
+ export const actions = {
9
+ default : async ( event ) => {
10
+ const formData = await event . request . formData ( ) ;
11
+ createPost ( event . params . id , formData . get ( 'content' ) ! . toString ( ) ) ;
12
+ }
13
+ } satisfies Actions ;
Original file line number Diff line number Diff line change
1
+ <script lang =" ts" >
2
+ import Pokemon from ' ../../../$lib/client/pokemon.svelte' ;
3
+ import type { PageData } from ' ./$types' ;
4
+ import { invalidate } from ' $app/navigation' ;
5
+ import RandomPokemonLink from ' ../../../$lib/client/randomPokemonLink.svelte' ;
6
+
7
+ export let data: PageData ;
8
+ const invalidateRoute = () => invalidate (` /pokemon/${data .id } ` );
9
+ </script >
10
+
11
+ <Pokemon id ={data .id } />
12
+ <div class =" p-8 flex flex-col items-center gap-1" >
13
+ <h2 class =" text-2xl" >Comments</h2 >
14
+ <div class =" p-8" >
15
+ {#each data .posts as post }
16
+ <article >
17
+ <span >{post .content }</span >
18
+ </article >
19
+ {/each }
20
+ <div />
21
+ </div >
22
+ </div >
23
+
24
+ <form class ="grid justify-items-center grid-flow-row" method ="post" on:submit ={invalidateRoute }>
25
+ <label for =" content" class =" text-xl" > Comment this Pokemon </label >
26
+ <textarea id =" content" name =" content" class =" ml-1 text-black" />
27
+ <input type =" submit" />
28
+ </form >
You can’t perform that action at this time.
0 commit comments