Skip to content

Commit

Permalink
API and static versions working
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmckenz committed Mar 11, 2024
1 parent cb1dde7 commit 975b178
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
.history
32 changes: 32 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
<script>
export let containers = [];
function showContainers() {
containers = [
{ id: 1, name: 'Container 1' },
{ id: 2, name: 'Container 2' },
] ;
}
</script>


<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>

<button on:click="{showContainers}">Show Containers</button>

{#each containers as container}
<div>
<span class="id">{container.id}</span>
<span class="name">{container.name}</span></div>
{/each}

<a href="/fromapi">Fetch from API</a>

<style>
.id {
margin-right: 10px;
font-weight: bold;
}
.name {
color: #999;
}
</style>
7 changes: 7 additions & 0 deletions src/routes/fromapi/+page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

export async function load({ fetch }) {
const res = await fetch(`http://localhost:3000/containers`);
const as_obj = await res.json();
//console.log({as_obj});
return as_obj;
}
23 changes: 23 additions & 0 deletions src/routes/fromapi/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script>
export let data;
//console.log({data});
</script>

<h1>Fetched from API</h1>

{#each data.containers as container}
<div>
<span class="id">{container.id}</span>
<span class="name">{container.nameOfShip}</span>
</div>
{/each}

<style>
.id {
margin-right: 10px;
font-weight: bold;
}
.name {
color: #999;
}
</style>

0 comments on commit 975b178

Please sign in to comment.