From 20a7a08e97e75c3a45b3430a74c2931554498f1c Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Mon, 7 Sep 2026 19:30:50 +0200 Subject: Extract shared groceries helpers and BestRef component --- src/routes/groceries/+page.svelte | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) (limited to 'src/routes/groceries/+page.svelte') diff --git a/src/routes/groceries/+page.svelte b/src/routes/groceries/+page.svelte index 4471738..a159209 100644 --- a/src/routes/groceries/+page.svelte +++ b/src/routes/groceries/+page.svelte @@ -3,6 +3,8 @@ import { goto } from '$app/navigation'; import { enhance } from '$app/forms'; import FuzzyAutocomplete from '$lib/components/FuzzyAutocomplete.svelte'; + import BestRef from '$lib/components/BestRef.svelte'; + import { groupByCategory } from '$lib/shared/group-by-category'; import type { EnrichedGrocery } from '$lib/server/services/groceries'; let { data, form } = $props(); @@ -15,21 +17,6 @@ localItems = data?.items ?? []; }); - function groupByCategory(items: typeof localItems) { - const groups: Record = {}; - for (const item of items) { - const key = item.categoryName ?? 'Non catégorisé'; - (groups[key] ??= []).push(item); - } - const result: [string, typeof localItems][] = data.categories - .filter((cat) => groups[cat.name]?.length > 0) - .map((cat) => [cat.name, groups[cat.name]]); - if (groups['Non catégorisé']?.length > 0) { - result.unshift(['Non catégorisé', groups['Non catégorisé']]); - } - return result; - } - async function handleAdd(redirectToEdit: boolean) { if (!name.trim()) { addError = 'Le nom est requis'; @@ -105,7 +92,7 @@

Rien à acheter

{:else}
- {#each groupByCategory(localItems) as [cat, items] (cat)} + {#each groupByCategory(localItems, data.categories) as [cat, items] (cat)}

{cat}

    {#each items as item (item.id)} @@ -120,16 +107,7 @@ {item.name} {#if item.bestRef} - {item.bestRef.reference} - {#if item.bestRef.price && item.bestRef.unit} -  {item.bestRef.price.toFixed(2)} - {item.bestRef.unit} - {/if} - {#if item.bestRef.qualityScore != null} -  ({item.bestRef.qualityScore}/100) - {/if} - + {/if} -- cgit v1.3