Skip to content
Snippets Groups Projects
Commit f424e8fa authored by David Trattnig's avatar David Trattnig
Browse files

Basic rendering of tracks.

parent 0a506deb
Branches
No related tags found
No related merge requests found
...@@ -17,4 +17,9 @@ Provided components: ...@@ -17,4 +17,9 @@ Provided components:
## Run ## Run
npm start npm start
\ No newline at end of file
## Resources
* Svelte Docs - https://svelte.dev/docs
\ No newline at end of file
<script> <script>
import TrackService from './TrackService.svelte'; import TrackService from './TrackService.svelte';
let query = "trackservice/3"; let queryTrackservice = "trackservice";
let result; let result;
async function getResult() { async function getData(query) {
// FIXME Configure DataURL and Port // FIXME Configure DataURL and Port
let response = await fetch(`http://localhost:3333/api/v1/${query}`); let response = await fetch(`http://localhost:3333/api/v1/${query}`);
let text = await response.text(); let data = await response.json();
let data = text;
return data;
}
function submitHandler() { if (response.ok) {
result = getResult(); return data;
query = ""; } else {
throw new Error(data)
}
} }
submitHandler();
result = getData(queryTrackservice);
</script> </script>
<div class="container mt-5"> <div class="container mt-5">
...@@ -26,30 +27,16 @@ ...@@ -26,30 +27,16 @@
<div class="col-md-8 text-center"> <div class="col-md-8 text-center">
<h1 class="display-4">Track Service</h1> <h1 class="display-4">Track Service</h1>
{#if result===undefined}
<p></p>
{:else}
{#await result} {#await result}
<div class="spinner-border mt-5" role="status">
<div class="spinner-border mt-5" role="status"> <span class="sr-only">Loading...</span>
<span class="sr-only">Loading...</span> </div>
</div>
{:then value} {:then value}
<TrackService data={value} />
<TrackService data={value} />
{:catch error} {:catch error}
<p style="color:red">{error.message}</p>
<TrackService data={error.message}/>
{/await} {/await}
{/if}
</div> </div>
<div class="col-md"></div> <div class="col-md"></div>
</div> </div>
......
...@@ -3,8 +3,11 @@ import { fly } from 'svelte/transition'; ...@@ -3,8 +3,11 @@ import { fly } from 'svelte/transition';
export let data; export let data;
</script> </script>
<div class="card mt-5" transition:fly="{{ y: 150, duration: 300 }}">
<div class="card-body"> {#each data as track}
<h5 class="card-title">{data}</h5> <div class="card mt-5" transition:fly="{{ y: 150, duration: 500 }}">
<div class="card-body">
<h5 class="card-title"><b>{track.track_start}</b>: {track.artist} - {track.title} ({track.duration})</h5>
</div>
</div> </div>
</div> {/each}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment