@@ -194,7 +194,11 @@ function ListingPhotosManager({
194194 uploadError ?. statusCode === "413" ||
195195 uploadError ?. error ?. statusCode === "413"
196196 ) {
197- alert ( overSizedFileAlertPlural ) ;
197+ alert (
198+ files . length === 1
199+ ? overSizedFileAlertSingular
200+ : overSizedFileAlertPlural
201+ ) ;
198202 } else if ( uploadError ?. message ?. includes ( "max_photos" ) ) {
199203 alert ( `You can only upload up to ${ MAX_PHOTOS } photos` ) ;
200204 } else {
@@ -208,6 +212,7 @@ function ListingPhotosManager({
208212 const handlePhotoDelete = async ( photoToDelete : string ) => {
209213 if ( isMutatingPhotos ) return ;
210214
215+ const deletedPhotoIndex = photosRef . current . indexOf ( photoToDelete ) ;
211216 setDeletingPhoto ( photoToDelete ) ;
212217 try {
213218 // Immediately remove from react-beautiful-dnd's context
@@ -221,11 +226,22 @@ function ListingPhotosManager({
221226 console . error ( "Error deleting photo:" , error ) ;
222227
223228 // Restore only the failed deletion, preserving other state changes.
224- updatePhotos ( ( currentPhotos ) =>
225- currentPhotos . includes ( photoToDelete )
226- ? currentPhotos
227- : [ ...currentPhotos , photoToDelete ]
228- ) ;
229+ updatePhotos ( ( currentPhotos ) => {
230+ if ( currentPhotos . includes ( photoToDelete ) ) {
231+ return currentPhotos ;
232+ }
233+
234+ const restoreIndex =
235+ deletedPhotoIndex === - 1
236+ ? currentPhotos . length
237+ : Math . min ( deletedPhotoIndex , currentPhotos . length ) ;
238+
239+ return [
240+ ...currentPhotos . slice ( 0 , restoreIndex ) ,
241+ photoToDelete ,
242+ ...currentPhotos . slice ( restoreIndex ) ,
243+ ] ;
244+ } ) ;
229245 alert ( "Failed to delete photo. Please try again." ) ;
230246 } finally {
231247 setDeletingPhoto ( null ) ;
0 commit comments