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
This commit is contained in:
@@ -220,6 +220,45 @@ export const actions: Actions = {
|
|||||||
// Delete from database
|
// Delete from database
|
||||||
imageRepository.delete(imageId);
|
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 };
|
return { success: true };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user