From c3bee2607b5e442a4fa87d617086a882e920f8e2 Mon Sep 17 00:00:00 2001 From: Till JS Date: Tue, 31 Mar 2026 13:34:52 +0200 Subject: [PATCH] refactor(todo): extract shared useTaskForm composable Extract 16 duplicated $state declarations, form initialization logic, and save/buildUpdateInput from TaskItem and TaskEditModal into a shared useTaskForm.svelte.ts composable. Uses getter/setter pattern for Svelte 5 bind:value compatibility. Eliminates ~200 lines of duplicated form state management. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/lib/components/TaskEditModal.svelte | 193 +++++--------- .../web/src/lib/components/TaskItem.svelte | 202 +++++---------- .../src/lib/composables/useTaskForm.svelte.ts | 244 ++++++++++++++++++ 3 files changed, 373 insertions(+), 266 deletions(-) create mode 100644 apps/todo/apps/web/src/lib/composables/useTaskForm.svelte.ts diff --git a/apps/todo/apps/web/src/lib/components/TaskEditModal.svelte b/apps/todo/apps/web/src/lib/components/TaskEditModal.svelte index 66d3c638f..91ef548f5 100644 --- a/apps/todo/apps/web/src/lib/components/TaskEditModal.svelte +++ b/apps/todo/apps/web/src/lib/components/TaskEditModal.svelte @@ -1,13 +1,5 @@ @@ -202,7 +110,7 @@ id="task-title" type="text" class="form-input" - bind:value={title} + bind:value={form.title} placeholder="Aufgabentitel..." /> @@ -213,7 +121,7 @@ @@ -223,15 +131,15 @@
(assignee = contacts)} + selectedContacts={form.assignee} + onContactsChange={(contacts) => (form.assignee = contacts)} onSearch={(q) => contactsStore.searchContacts(q)} singleSelect={true} allowManualEntry={false} placeholder="Person zuweisen..." addLabel="Zuweisen" searchPlaceholder="Name oder E-Mail..." - isAvailable={contactsAvailable ?? false} + isAvailable={form.contactsAvailable ?? false} />
@@ -239,14 +147,14 @@
(involvedContacts = contacts)} + selectedContacts={form.involvedContacts} + onContactsChange={(contacts) => (form.involvedContacts = contacts)} onSearch={(q) => contactsStore.searchContacts(q)} allowManualEntry={false} placeholder="Personen hinzufügen..." addLabel="Person hinzufügen" searchPlaceholder="Name oder E-Mail..." - isAvailable={contactsAvailable ?? false} + isAvailable={form.contactsAvailable ?? false} />
@@ -256,15 +164,20 @@
- +
- +
- +
@@ -272,13 +185,13 @@
- (priority = p)} /> + (form.priority = p)} />
- {#each STATUS_OPTIONS as s} {/each} @@ -288,7 +201,7 @@
- {#each getActiveProjects(projectsCtx.value) as project}