From 17183632c8a4d383237024cdfa9cb43f63cb3484 Mon Sep 17 00:00:00 2001 From: Swift Coder Date: Fri, 11 Oct 2024 12:50:26 -0400 Subject: [PATCH] Multiple images upload --- damus/Views/MediaPicker.swift | 2 +- damus/Views/PostView.swift | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/damus/Views/MediaPicker.swift b/damus/Views/MediaPicker.swift index d03598e4..44336435 100644 --- a/damus/Views/MediaPicker.swift +++ b/damus/Views/MediaPicker.swift @@ -115,7 +115,7 @@ struct MediaPicker: UIViewControllerRepresentable { func makeUIViewController(context: Context) -> PHPickerViewController { var configuration = PHPickerConfiguration(photoLibrary: .shared()) - configuration.selectionLimit = 1 + configuration.selectionLimit = 0 // Allows multiple media selection configuration.filter = imagesOnly ? .images : .any(of: [.images, .videos]) let picker = PHPickerViewController(configuration: configuration) diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift index 2aab4298..6abb974a 100644 --- a/damus/Views/PostView.swift +++ b/damus/Views/PostView.swift @@ -60,7 +60,7 @@ struct PostView: View { @State var newCursorIndex: Int? @State var textHeight: CGFloat? = nil - @State var preUploadedMedia: PreUploadedMedia? = nil + @State var preUploadedMedia: [PreUploadedMedia] = [] @StateObject var image_upload: ImageUploadModel = ImageUploadModel() @StateObject var tagModel: TagModel = TagModel() @@ -151,6 +151,7 @@ struct PostView: View { var ImageButton: some View { Button(action: { + preUploadedMedia.removeAll() attach_media = true }, label: { Image("images") @@ -445,16 +446,20 @@ struct PostView: View { .background(DamusColors.adaptableWhite.edgesIgnoringSafeArea(.all)) .sheet(isPresented: $attach_media) { MediaPicker(image_upload_confirm: $image_upload_confirm){ media in - self.preUploadedMedia = media + self.preUploadedMedia.append(media) } - .alert(NSLocalizedString("Are you sure you want to upload this media?", comment: "Alert message asking if the user wants to upload media."), isPresented: $image_upload_confirm) { + .alert(NSLocalizedString("Are you sure you want to upload the selected media?", comment: "Alert message asking if the user wants to upload media."), isPresented: $image_upload_confirm) { Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) { - if let mediaToUpload = generateMediaUpload(preUploadedMedia) { - self.handle_upload(media: mediaToUpload) - self.attach_media = false + for media in preUploadedMedia { + if let mediaToUpload = generateMediaUpload(media) { + self.handle_upload(media: mediaToUpload) + } } + self.attach_media = false + } + Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) { + preUploadedMedia.removeAll() } - Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) {} } } .sheet(isPresented: $attach_camera) { @@ -486,6 +491,7 @@ struct PostView: View { if isEmpty() { clear_draft() } + preUploadedMedia.removeAll() } } }