From a232a95cedad9e69d258a130016bbc85d592d4cc Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Sat, 31 Jan 2026 13:02:55 +0100 Subject: [PATCH] feat(04-02): add togglePin and updateDueDate form actions - Add togglePin action to toggle entry.pinned boolean state - Add updateDueDate action to set/clear entry.dueDate - Both actions validate entry exists before updating --- src/routes/+page.server.ts | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 8942480..c9d28e5 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -220,6 +220,45 @@ export const actions: Actions = { // Delete from database imageRepository.delete(imageId); + return { success: true }; + }, + + togglePin: async ({ request }) => { + const formData = await request.formData(); + const id = formData.get('id')?.toString(); + + if (!id) { + return fail(400, { error: 'Entry ID is required' }); + } + + const existing = entryRepository.getById(id); + if (!existing) { + return fail(404, { error: 'Entry not found' }); + } + + // Toggle pinned state + entryRepository.update(id, { pinned: !existing.pinned }); + + return { success: true }; + }, + + updateDueDate: async ({ request }) => { + const formData = await request.formData(); + const id = formData.get('id')?.toString(); + const dueDate = formData.get('dueDate')?.toString() || null; + + if (!id) { + return fail(400, { error: 'Entry ID is required' }); + } + + const existing = entryRepository.getById(id); + if (!existing) { + return fail(404, { error: 'Entry not found' }); + } + + // Update due date (empty string becomes null) + entryRepository.update(id, { dueDate: dueDate || null }); + return { success: true }; } };