StatCards - fetch real data from API

ref #10
This commit is contained in:
Philipp Dormann 2020-12-31 16:19:58 +01:00
parent e9a6637eb9
commit 3d93b04264

View File

@ -1,8 +1,23 @@
<script>
import { _ } from "svelte-i18n";
import { TrackService, StatsService } from "@odit/lfk-client-js";
const stats_promise = StatsService.statsControllerGet();
stats_promise.then((res) => {
console.log(res);
});
</script>
<div
<!-- -->
<h1>Allgemeine Statistiken</h1>
{#await stats_promise}
<div
class="bg-teal-lightest border-t-4 border-teal rounded-b text-teal-darkest px-4 py-3 shadow-md my-2"
role="alert">
<p class="font-bold">stats are being loaded...</p>
<p class="text-sm">This might take a moment 👀</p>
</div>
{:then stats}
<div
class="flex flex-col lg:flex-row w-full lg:space-x-2 space-y-2 lg:space-y-0 mb-2 lg:mb-4">
<div class="w-full lg:w-1/4">
<div
@ -12,7 +27,7 @@
<div class="text-xs uppercase font-light text-grey-500">
{$_('runners')}
</div>
<div class="text-xl font-bold">69</div>
<div class="text-xl font-bold">{stats.total_runners}</div>
</div><svg
stroke="currentColor"
fill="none"
@ -40,7 +55,7 @@
<div class="text-xs uppercase font-light text-grey-500">
{$_('total-scans')}
</div>
<div class="text-xl font-bold">1500</div>
<div class="text-xl font-bold">{stats.total_scans}</div>
</div><svg
stroke="currentColor"
fill="none"
@ -65,7 +80,7 @@
<div class="text-xs uppercase font-light text-grey-500">
{$_('total-donations')}
</div>
<div class="text-xl font-bold">5000,00 €</div>
<div class="text-xl font-bold">{stats.total_donation}</div>
</div><svg
xmlns="http://www.w3.org/2000/svg"
height="24"
@ -83,7 +98,10 @@
<div class="text-xs uppercase font-light text-grey-500">
{$_('total-distance')}
</div>
<div class="text-xl font-bold">100.0 km</div>
<div class="text-xl font-bold">
{stats.total_distance / 1000}
km
</div>
</div>
<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path
d="M0 0h24v24H0z"
@ -93,4 +111,12 @@
</div>
</div>
</div>
</div>
</div>
{:catch error}
<div class="text-white px-6 py-4 border-0 rounded relative mb-4 bg-red-500">
<span class="inline-block align-middle mr-8">
<b class="capitalize">😢 Error</b>
{error}
</span>
</div>
{/await}