From b323f02654dfd964283c0a15cfffbb713005e394 Mon Sep 17 00:00:00 2001 From: Andrii Solianyk Date: Wed, 11 Jun 2025 19:04:56 +0200 Subject: [PATCH] isMainImage przekazywane na Backend --- ArtisanConnect/api/notices.jsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ArtisanConnect/api/notices.jsx b/ArtisanConnect/api/notices.jsx index b13805a..ab61fe0 100644 --- a/ArtisanConnect/api/notices.jsx +++ b/ArtisanConnect/api/notices.jsx @@ -39,8 +39,14 @@ export async function createNotice(notice) { }); if (response.data.noticeId !== null) { - for (const imageUri of notice.image) { - await uploadImage(response.data.noticeId, imageUri); + for (const image of notice.image) { + console.log("image", image); + if(notice.image.indexOf(image) === 0) { + console.log("Image is first:", image); + await uploadImage(response.data.noticeId, image, true); + } + console.log("image", image); + await uploadImage(response.data.noticeId, image, false); } } @@ -94,7 +100,7 @@ export async function getAllImagesByNoticeId(noticeId) { } } -export const uploadImage = async (noticeId, imageUri) => { +export const uploadImage = async (noticeId, imageObj, isFirst) => { const { token } = useAuthStore.getState(); const headers = { ...(token ? { Authorization: `Bearer ${token}` } : {}), @@ -102,20 +108,20 @@ export const uploadImage = async (noticeId, imageUri) => { }; const formData = new FormData(); - const filename = imageUri.split("/").pop(); + const filename = imageObj.split("/").pop(); const match = /\.(\w+)$/.exec(filename); const type = match ? `image/${match[1]}` : "image/jpeg"; formData.append("file", { - uri: imageUri, + uri: imageObj, name: filename, type: type, }); try { const response = await axios.post( - `${API_URL}/images/upload/${noticeId}`, + `${API_URL}/images/upload/${noticeId}?isMainImage=${isFirst}`, formData, { headers: headers, @@ -124,7 +130,7 @@ export const uploadImage = async (noticeId, imageUri) => { console.info("Upload successful:", response.data); return response.data; } catch (error) { - console.log("imageURI:", imageUri); + console.log("imageURI:", imageObj); console.error( "Error uploading image:",