From 549aacb9997878850c1ddda0c7b8fd37b9c3420e Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Wed, 28 Aug 2024 09:56:20 +0200 Subject: [PATCH] correct some mistatkes --- src/lib/components/Childrenpage.svelte | 43 ++++++++++++++------------ src/lib/stores/childrenStore.ts | 13 +++++--- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/lib/components/Childrenpage.svelte b/src/lib/components/Childrenpage.svelte index 0dddcc7e..26bece61 100644 --- a/src/lib/components/Childrenpage.svelte +++ b/src/lib/components/Childrenpage.svelte @@ -54,40 +54,43 @@ children, createDummyData, fetchChildrenDataforUser, - type ChildData, - type ChildrenList + type ChildData } from '$lib/stores/childrenStore'; import { Heading } from 'flowbite-svelte'; - import { onDestroy, onMount } from 'svelte'; + import { onMount } from 'svelte'; // create data and let data: ChildData[] = []; + let loading = true; - const unsubscribe = children.subscribe(async (childlist: ChildrenList) => { + async function init() { + loading = true; + children.set({}); + await createDummyData(); let rawdata = await fetchChildrenDataforUser('dummyUser'); data = convertData(rawdata); - }); + loading = false; + } // this fetches dummy child data for the dummy user whenever the component is mounted into the dom // it is conceptualized as emulating an API call that would normally fetch this from the server. - onMount(async () => { - children.set({}); - await createDummyData(); - }); - - onDestroy(unsubscribe); + onMount(init); Übersicht
-

- Wählen sie ein Kind zur Beobachtung aus oder legen melden sie ein neues Kind an. -

- + {#if loading} +

Daten werden geladen...

+ {:else} +

+ Wählen sie ein Kind zur Beobachtung aus oder legen melden sie ein neues Kind an. +

+ + {/if}
diff --git a/src/lib/stores/childrenStore.ts b/src/lib/stores/childrenStore.ts index 98151fab..9d936bd3 100644 --- a/src/lib/stores/childrenStore.ts +++ b/src/lib/stores/childrenStore.ts @@ -9,6 +9,7 @@ interface ObservationData { } interface ChildData { + name: string; [key: string]: unknown; } @@ -128,13 +129,17 @@ async function fetchObservationData(usertoken: string, childtoken: string) { async function fetchChildrenDataforUser(usertoken: string) { const contentData = get(children); + if (!(usertoken in contentData)) { throw new Error('No such user in the childrenstore'); } - return Object.keys(contentData[usertoken]).map((child) => { - return contentData[usertoken][child].childData; - }); + // sort them alphabetically + return Object.keys(contentData[usertoken]) + .map((child) => { + return contentData[usertoken][child].childData; + }) + .sort((a, b) => a.name.localeCompare(b.name)); } async function fetchObservationDataForUser(usertoken: string) { const contentData = get(children); @@ -143,7 +148,7 @@ async function fetchObservationDataForUser(usertoken: string) { } return Object.keys(contentData[usertoken]).map((child) => { - return contentData[usertoken][child].observationData; + return [child, contentData[usertoken][child].observationData]; }); }