From 5e2132469209f62ccc997500e7120cb3e02bb79b Mon Sep 17 00:00:00 2001 From: Emmanuel Raviart <emmanuel@raviart.com> Date: Thu, 5 Dec 2024 14:33:15 +0100 Subject: [PATCH] Fix adding & removing children & parents --- .../components/test_cases/TestCaseEdit.svelte | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/lib/components/test_cases/TestCaseEdit.svelte b/src/lib/components/test_cases/TestCaseEdit.svelte index 164b5965d..e5f381358 100644 --- a/src/lib/components/test_cases/TestCaseEdit.svelte +++ b/src/lib/components/test_cases/TestCaseEdit.svelte @@ -122,16 +122,13 @@ async function addPerson(id: string, isChild: boolean): Promise<void> { const entity = entityByKey[personEntityKey] - const personById = { - ...situation[entity.key_plural], - } + const personById = situation[entity.key_plural] const person = (personById[id] = {} as PopulationWithoutId) if (isChild) { person.date_naissance = { [year]: new Date(year - 10, 6, 2).toISOString().split("T")[0], } } - situation = { ...situation, [entity.key_plural]: personById } for (const groupEntity of Object.values(entityByKey) as GroupEntity[]) { if (groupEntity.is_person) { @@ -472,18 +469,12 @@ let personById = $derived( Object.fromEntries(persons.map((person) => [person.id, person])), ) - let adultsId - run(() => { - adultsId = [ - ...Object.keys(personById).filter((id) => id.startsWith("Adulte ")), - ] - }) - let childrenId - run(() => { - childrenId = [ - ...Object.keys(personById).filter((id) => id.startsWith("Enfant ")), - ] - }) + let adultsId = $state([ + ...Object.keys(personById).filter((id) => id.startsWith("Adulte ")), + ]) + let childrenId = $state([ + ...Object.keys(personById).filter((id) => id.startsWith("Enfant ")), + ]) let adultSituations = $derived( Object.entries(situation[personEntity.key_plural] ?? {}) .filter(([id]) => id.startsWith("Adulte ")) -- GitLab