From 684d3c954e3577a6488101bf5ee85e36439fd53c Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Wed, 29 Jul 2026 10:31:36 +0200 Subject: feat: multi-select and bulk-update category from catalog --- src/routes/catalog/+page.server.ts | 25 +++++++++- src/routes/catalog/+page.svelte | 97 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 2 deletions(-) (limited to 'src/routes/catalog') diff --git a/src/routes/catalog/+page.server.ts b/src/routes/catalog/+page.server.ts index 69a775a..22464dc 100644 --- a/src/routes/catalog/+page.server.ts +++ b/src/routes/catalog/+page.server.ts @@ -1,6 +1,13 @@ import { fail } from '@sveltejs/kit'; -import { loadAll, toggle } from '$lib/server/services/groceries'; -import { numericId } from '$lib/server/services/validation'; +import { + loadAll, + toggle, + bulkUpdateGroceryCategory, +} from '$lib/server/services/groceries'; +import { + numericId, + parseOptionalNumber, +} from '$lib/server/services/validation'; import type { EnrichedGrocery } from '$lib/server/services/groceries'; import type { Category } from '$lib/server/services/types'; import type { Actions, PageServerLoad } from './$types'; @@ -25,4 +32,18 @@ export const actions: Actions = { } return { success: true }; }, + + bulkUpdateCategory: async ({ request }) => { + const data = await request.formData(); + const ids = data.getAll('ids').map(numericId); + const rawCategoryId = parseOptionalNumber(data.get('category_id')); + const categoryId = rawCategoryId === -1 ? null : rawCategoryId; + + if (ids.length === 0) { + return fail(400, { error: 'Aucun article sélectionné' }); + } + + await bulkUpdateGroceryCategory(ids, categoryId); + return { success: true, type: 'bulkUpdate' as const }; + }, }; diff --git a/src/routes/catalog/+page.svelte b/src/routes/catalog/+page.svelte index 7d3ebbe..2079d12 100644 --- a/src/routes/catalog/+page.svelte +++ b/src/routes/catalog/+page.svelte @@ -1,9 +1,16 @@ +{#if catalogItems.length > 0} +
+
{ + return async ({ update }) => { + await update({ reset: false }); + selectedIds.clear(); + }; + }} + > + {#each Array.from(selectedIds) as id (id)} + + {/each} + + +
+
+{/if} +
+ {#if form?.error} +

{form.error}

+ {/if} + {#if catalogItems.length === 0}

Aucun article

{:else} @@ -25,6 +68,12 @@