Banner Image Upload
Changelog-Added: Enable banner image editing
This commit is contained in:
committed by
William Casarin
parent
e316d5d635
commit
bf95a8b328
@@ -25,7 +25,9 @@ struct EditMetadataView: View {
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
@State var confirm_ln_address: Bool = false
|
||||
@StateObject var profileUploadViewModel = ProfileUploadingViewModel()
|
||||
|
||||
@StateObject var profileUploadObserver = ImageUploadingObserver()
|
||||
@StateObject var bannerUploadObserver = ImageUploadingObserver()
|
||||
|
||||
init (damus_state: DamusState) {
|
||||
self.damus_state = damus_state
|
||||
@@ -78,7 +80,7 @@ struct EditMetadataView: View {
|
||||
var TopSection: some View {
|
||||
ZStack(alignment: .top) {
|
||||
GeometryReader { geo in
|
||||
BannerImageView(pubkey: damus_state.pubkey, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)
|
||||
EditBannerImageView(damus_state: damus_state, viewModel: bannerUploadObserver, callback: uploadedBanner(image_url:))
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(width: geo.size.width, height: BANNER_HEIGHT)
|
||||
.clipped()
|
||||
@@ -87,7 +89,7 @@ struct EditMetadataView: View {
|
||||
let pfp_size: CGFloat = 90.0
|
||||
|
||||
HStack(alignment: .center) {
|
||||
ProfilePictureSelector(pubkey: damus_state.pubkey, damus_state: damus_state, viewModel: profileUploadViewModel, callback: uploadedProfilePicture(image_url:))
|
||||
ProfilePictureSelector(pubkey: damus_state.pubkey, damus_state: damus_state, uploadObserver: profileUploadObserver, callback: uploadedProfilePicture(image_url:))
|
||||
.offset(y: -(pfp_size/2.0)) // Increase if set a frame
|
||||
|
||||
Spacer()
|
||||
@@ -182,7 +184,7 @@ struct EditMetadataView: View {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
.disabled(profileUploadViewModel.isLoading)
|
||||
.disabled(profileUploadObserver.isLoading || bannerUploadObserver.isLoading)
|
||||
.alert(NSLocalizedString("Invalid Tip Address", comment: "Title of alerting as invalid tip address."), isPresented: $confirm_ln_address) {
|
||||
Button(NSLocalizedString("Ok", comment: "Button to dismiss the alert.")) {
|
||||
}
|
||||
@@ -198,6 +200,10 @@ struct EditMetadataView: View {
|
||||
func uploadedProfilePicture(image_url: URL?) {
|
||||
picture = image_url?.absoluteString ?? ""
|
||||
}
|
||||
|
||||
func uploadedBanner(image_url: URL?) {
|
||||
banner = image_url?.absoluteString ?? ""
|
||||
}
|
||||
}
|
||||
|
||||
struct EditMetadataView_Previews: PreviewProvider {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// ProfilePictureEditView.swift
|
||||
// EditPictureControl.swift
|
||||
// damus
|
||||
//
|
||||
// Created by Joel Klabo on 3/30/23.
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct EditProfilePictureControl: View {
|
||||
struct EditPictureControl: View {
|
||||
let uploader: MediaUploader
|
||||
let pubkey: String
|
||||
@Binding var profile_image: URL?
|
||||
@ObservedObject var viewModel: ProfileUploadingViewModel
|
||||
@Binding var image_url: URL?
|
||||
@ObservedObject var uploadObserver: ImageUploadingObserver
|
||||
let callback: (URL?) -> Void
|
||||
|
||||
@StateObject var image_upload: ImageUploadModel = ImageUploadModel()
|
||||
@@ -36,7 +36,7 @@ struct EditProfilePictureControl: View {
|
||||
Text("Take Photo", comment: "Option to take a photo with the camera")
|
||||
}
|
||||
} label: {
|
||||
if viewModel.isLoading {
|
||||
if uploadObserver.isLoading {
|
||||
ProgressView()
|
||||
} else {
|
||||
Image("camera")
|
||||
@@ -83,14 +83,14 @@ struct EditProfilePictureControl: View {
|
||||
}
|
||||
|
||||
private func handle_upload(media: MediaUpload) {
|
||||
viewModel.isLoading = true
|
||||
uploadObserver.isLoading = true
|
||||
Task {
|
||||
let res = await image_upload.start(media: media, uploader: uploader)
|
||||
|
||||
switch res {
|
||||
case .success(let urlString):
|
||||
let url = URL(string: urlString)
|
||||
profile_image = url
|
||||
image_url = url
|
||||
callback(url)
|
||||
case .failed(let error):
|
||||
if let error {
|
||||
@@ -100,7 +100,7 @@ struct EditProfilePictureControl: View {
|
||||
}
|
||||
callback(nil)
|
||||
}
|
||||
viewModel.isLoading = false
|
||||
uploadObserver.isLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import SwiftUI
|
||||
|
||||
import Combine
|
||||
|
||||
class ProfileUploadingViewModel: ObservableObject {
|
||||
class ImageUploadingObserver: ObservableObject {
|
||||
@Published var isLoading: Bool = false
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ struct ProfilePictureSelector: View {
|
||||
let pubkey: String
|
||||
var size: CGFloat = 80.0
|
||||
var damus_state: DamusState?
|
||||
@ObservedObject var viewModel: ProfileUploadingViewModel
|
||||
@ObservedObject var uploadObserver: ImageUploadingObserver
|
||||
let callback: (URL?) -> Void
|
||||
|
||||
@State var profile_image: URL? = nil
|
||||
@@ -31,7 +31,7 @@ struct ProfilePictureSelector: View {
|
||||
let highlight: Highlight = .custom(Color.white, 2.0)
|
||||
ZStack {
|
||||
EditProfilePictureView(url: $profile_image, pubkey: pubkey, size: size, highlight: highlight, damus_state: damus_state)
|
||||
EditProfilePictureControl(uploader: uploader, pubkey: pubkey, profile_image: $profile_image, viewModel: viewModel, callback: callback)
|
||||
EditPictureControl(pubkey: pubkey, image_url: $profile_image, uploadObserver: uploadObserver, callback: callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ struct ProfilePictureSelector: View {
|
||||
struct ProfilePictureSelector_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let test_pubkey = "ff48854ac6555fed8e439ebb4fa2d928410e0eef13fa41164ec45aaaa132d846"
|
||||
ProfilePictureSelector(pubkey: test_pubkey, viewModel: ProfileUploadingViewModel()) { _ in
|
||||
ProfilePictureSelector(pubkey: test_pubkey, uploadObserver: ImageUploadingObserver()) { _ in
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user