From 6dbfc07a513e840fde5fa03bbaac54692ae3b1e9 Mon Sep 17 00:00:00 2001 From: Barrett Burnworth <77902178+pantheredeye@users.noreply.github.com> Date: Wed, 4 Dec 2024 19:13:40 -0600 Subject: [PATCH] chore: fix media upload --- .../NewInspectionPage/NewInspectionPage.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/web/src/pages/NewInspectionPage/NewInspectionPage.tsx b/web/src/pages/NewInspectionPage/NewInspectionPage.tsx index cbd9651..6e26e36 100644 --- a/web/src/pages/NewInspectionPage/NewInspectionPage.tsx +++ b/web/src/pages/NewInspectionPage/NewInspectionPage.tsx @@ -141,7 +141,7 @@ const NewInspectionPage = () => { Object.keys(data).forEach((key) => { const match = key.match(/(.*)-(\d+)/) - if (match) { + if (match && !key.startsWith('media-description')) { const fieldName = match[1] const bmpId = parseInt(match[2], 10) if (!bmpData[bmpId]) { @@ -162,10 +162,17 @@ const NewInspectionPage = () => { ? parseFloat(cleanedData.approximatePrecipitation) : null - data.media = media.map((item) => ({ - url: item.url, - description: item.description, - })) + data.media = media.map((item, index) => { + const descriptionKey = `media-description-${index}` + const mediaItem = { + url: item.url, + description: data[descriptionKey] || '', // Attach description + } + + delete cleanedData[descriptionKey] + + return mediaItem + }) await createInspection({ variables: {