diff --git a/src/routes/start/+page.server.ts b/src/routes/start/+page.server.ts index af2f8ec..0f5eaae 100644 --- a/src/routes/start/+page.server.ts +++ b/src/routes/start/+page.server.ts @@ -171,13 +171,22 @@ export const actions: Actions = { /** Reorder: `order` is the full list of link ids in their new order. */ orderLinks: async (event) => { if (!owner(event)) return fail(404, { message: 'Not Found' }); - const raw = String((await event.request.formData()).get('order') ?? ''); + const form = await event.request.formData(); + const raw = String(form.get('order') ?? ''); const ids = raw .split(',') .map(Number) .filter((n) => Number.isInteger(n) && n > 0); if (!ids.length || ids.length > 500) return fail(400, { message: 'Invalid order' }); + // Optional: drag-and-drop into another section moves link `id` there too. + const moveId = intId(form.get('id')); + const section = form.has('section') + ? linkInput.shape.section.safeParse(form.get('section')) + : null; + if (section && !section.success) return fail(400, { message: 'Invalid section' }); await db.transaction(async (tx) => { + if (moveId && section?.success) + await tx.update(homeLinks).set({ section: section.data }).where(eq(homeLinks.id, moveId)); for (const [i, id] of ids.entries()) await tx .update(homeLinks) diff --git a/src/routes/start/+page.svelte b/src/routes/start/+page.svelte index 70a62b5..06750c8 100644 --- a/src/routes/start/+page.svelte +++ b/src/routes/start/+page.svelte @@ -1,6 +1,6 @@