damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 3284832eb05c163cb74072cae19087eff5e35e57
parent c679be96442b8020db82fb40b7061affbfa33f41
Author: Swift <scoder1747@gmail.com>
Date:   Tue, 18 Apr 2023 10:37:32 -0400

Fix camera not dismissing

Changelog-Fixed: Fix camera not dismissing
Closes: #964

Diffstat:
Mdamus/Views/PostView.swift | 17+++++++++++++----
Mdamus/Views/Profile/EditProfilePictureControl.swift | 28++++++++++++++++++++++++----
2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift @@ -350,7 +350,7 @@ struct PostView: View { } onVideoPicked: { url in self.mediaToUpload = .video(url) } - .alert(NSLocalizedString("Are you sure you want to upload this image?", comment: "Alert message asking if the user wants to upload an image."), isPresented: $image_upload_confirm) { + .alert(NSLocalizedString("Are you sure you want to upload this media?", comment: "Alert message asking if the user wants to upload an image."), isPresented: $image_upload_confirm) { Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) { if let mediaToUpload { self.handle_upload(media: mediaToUpload) @@ -361,11 +361,20 @@ struct PostView: View { } } .sheet(isPresented: $attach_camera) { - // image_upload_confirm isn't handled here, I don't know we need to display it here too tbh + ImagePicker(uploader: damus_state.settings.default_media_uploader, sourceType: .camera, pubkey: damus_state.pubkey, image_upload_confirm: $image_upload_confirm) { img in - handle_upload(media: .image(img)) + self.mediaToUpload = .image(img) } onVideoPicked: { url in - handle_upload(media: .video(url)) + self.mediaToUpload = .video(url) + } + .alert("Are you sure you want to upload this media?", isPresented: $image_upload_confirm) { + Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) { + if let mediaToUpload { + self.handle_upload(media: mediaToUpload) + self.attach_camera = false + } + } + Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) {} } } .onAppear() { diff --git a/damus/Views/Profile/EditProfilePictureControl.swift b/damus/Views/Profile/EditProfilePictureControl.swift @@ -20,6 +20,8 @@ struct EditProfilePictureControl: View { @State private var show_library = false @State var image_upload_confirm: Bool = false + @State var mediaToUpload: MediaUpload? = nil + var body: some View { Menu { Button(action: { @@ -45,20 +47,38 @@ struct EditProfilePictureControl: View { } } .sheet(isPresented: $show_camera) { - // The alert may not be required for the profile pic upload case. Not showing the confirm check alert for this scenario + ImagePicker(uploader: uploader, sourceType: .camera, pubkey: pubkey, image_upload_confirm: $image_upload_confirm, imagesOnly: true) { img in - handle_upload(media: .image(img)) + self.mediaToUpload = .image(img) } onVideoPicked: { url in print("Cannot upload videos as profile image") } + .alert("Are you sure you want to upload this image?", isPresented: $image_upload_confirm) { + Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) { + if let mediaToUpload { + self.handle_upload(media: mediaToUpload) + self.show_camera = false + } + } + Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) {} + } } .sheet(isPresented: $show_library) { - // The alert may not be required for the profile pic upload case. Not showing the confirm check alert for this scenario ImagePicker(uploader: uploader, sourceType: .photoLibrary, pubkey: pubkey, image_upload_confirm: $image_upload_confirm, imagesOnly: true) { img in - handle_upload(media: .image(img)) + self.mediaToUpload = .image(img) + } onVideoPicked: { url in print("Cannot upload videos as profile image") } + .alert("Are you sure you want to upload this image?", isPresented: $image_upload_confirm) { + Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) { + if let mediaToUpload { + self.handle_upload(media: mediaToUpload) + self.show_library = false + } + } + Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) {} + } } }