diff --git a/src/routes/(app)/devices/[id]/+page.svelte b/src/routes/(app)/devices/[id]/+page.svelte index 641bbf4..3a55334 100644 --- a/src/routes/(app)/devices/[id]/+page.svelte +++ b/src/routes/(app)/devices/[id]/+page.svelte @@ -15,6 +15,26 @@ let showImportChecklist = $state(false); let editingChecklistId = $state(null); let editingChecklistItemId = $state(null); + let collapsedChecklists = $state>(new Set()); + + // Auto-collapse completed checklists on load + $effect(() => { + const newCollapsed = new Set(); + for (const cl of data.checklists) { + if (cl.items.length > 0) { + const allDone = cl.items.every((i: any) => i.itemType === 'input' ? !!i.value : i.checked); + if (allDone) newCollapsed.add(cl.id); + } + } + collapsedChecklists = newCollapsed; + }); + + function toggleChecklist(id: string) { + const next = new Set(collapsedChecklists); + if (next.has(id)) next.delete(id); + else next.add(id); + collapsedChecklists = next; + } function resetInput(formEl: HTMLFormElement) { const input = formEl.querySelector('input[name="text"]') as HTMLInputElement; const unit = formEl.querySelector('input[name="unit"]') as HTMLInputElement; @@ -383,8 +403,30 @@ {:else}
{#each data.checklists as checklist} + {@const clCompleted = checklist.items.filter((i: any) => i.itemType === 'input' ? !!i.value : i.checked).length} + {@const clTotal = checklist.items.length} + {@const clPct = clTotal > 0 ? Math.round((clCompleted / clTotal) * 100) : 0} + {@const isCollapsed = collapsedChecklists.has(checklist.id)}
-
+ + +
+ {#if editingChecklistId === checklist.id}
{ return async ({ update, result }) => { @@ -398,13 +440,9 @@
- {:else} -

{checklist.title}

{/if}
- - {checklist.items.filter((i: any) => i.itemType === 'input' ? !!i.value : i.checked).length}/{checklist.items.length} - + {clCompleted}/{clTotal} {#if editingChecklistId !== checklist.id}
- - {#if checklist.items.length > 0} - {@const completed = checklist.items.filter((i: any) => i.itemType === 'input' ? !!i.value : i.checked).length} - {@const pct = Math.round((completed / checklist.items.length) * 100)} -
-
+ + {#if clTotal > 0} +
+
{/if} + {#if !isCollapsed} -
+
{#each checklist.items as item, idx} {#if editingChecklistItemId === item.id} @@ -555,6 +592,7 @@ + {/if}
{/each}