From 3ed2f28f2ebb674b94768f7a431f91af1bfa1f1d Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Tue, 4 Feb 2025 09:22:14 -0600 Subject: [PATCH] Fix favorite form bug --- src/photo/form/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/photo/form/index.ts b/src/photo/form/index.ts index 80c936db..58711d2d 100644 --- a/src/photo/form/index.ts +++ b/src/photo/form/index.ts @@ -242,9 +242,16 @@ export const convertFormDataToPhotoDbInsert = ( ? Object.fromEntries(formData) as PhotoFormData : formData; + // Capture tags before 'favorite' is excluded from insert + const tags = convertStringToArray(photoForm.tags) ?? []; + if (photoForm.favorite === 'true') { + tags.push(TAG_FAVS); + } + // Parse FormData: // - remove server action ID // - remove empty strings + // - remove fields excluded from insert // - trim strings Object.keys(photoForm).forEach(key => { const meta = FORM_METADATA()[key as keyof PhotoFormData]; @@ -259,11 +266,6 @@ export const convertFormDataToPhotoDbInsert = ( } }); - const tags = convertStringToArray(photoForm.tags) ?? []; - if (photoForm.favorite === 'true') { - tags.push(TAG_FAVS); - } - return { ...(photoForm as PhotoFormData & { filmSimulation?: FilmSimulation }), ...!photoForm.id && { id: generateNanoid() },