image edit fix in profile
This commit is contained in:
parent
fc3a534496
commit
c7f51b30cd
@ -154,11 +154,27 @@ struct EditProfileView: View {
|
|||||||
.fill(Color.secondary.opacity(0.2))
|
.fill(Color.secondary.opacity(0.2))
|
||||||
.frame(width: 120, height: 120)
|
.frame(width: 120, height: 120)
|
||||||
.overlay(
|
.overlay(
|
||||||
Image(systemName: "person.fill")
|
Text(profileInitials)
|
||||||
.font(.system(size: 60))
|
.font(.system(size: 48, weight: .semibold))
|
||||||
.foregroundColor(.gray)
|
.foregroundColor(.gray)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var profileInitials: String {
|
||||||
|
if let initials = initials(from: displayName) {
|
||||||
|
return initials
|
||||||
|
}
|
||||||
|
if let profile = profile,
|
||||||
|
let name = profile.fullName?.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||||
|
!name.isEmpty,
|
||||||
|
let initials = initials(from: name) {
|
||||||
|
return initials
|
||||||
|
}
|
||||||
|
if let username = profile?.login.trimmingCharacters(in: .whitespacesAndNewlines), !username.isEmpty {
|
||||||
|
return String(username.prefix(1)).uppercased()
|
||||||
|
}
|
||||||
|
return "?"
|
||||||
|
}
|
||||||
|
|
||||||
private func avatarUrl(for profile: ProfileDataPayload, fileId: String) -> URL? {
|
private func avatarUrl(for profile: ProfileDataPayload, fileId: String) -> URL? {
|
||||||
return URL(string: "\(AppConfig.API_SERVER)/v1/storage/download/avatar/\(profile.userId)?file_id=\(fileId)")
|
return URL(string: "\(AppConfig.API_SERVER)/v1/storage/download/avatar/\(profile.userId)?file_id=\(fileId)")
|
||||||
@ -360,6 +376,15 @@ struct EditProfileView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func initials(from text: String) -> String? {
|
||||||
|
let components = text
|
||||||
|
.split { $0.isWhitespace }
|
||||||
|
.filter { !$0.isEmpty }
|
||||||
|
let letters = components.prefix(2).compactMap { $0.first }
|
||||||
|
guard !letters.isEmpty else { return nil }
|
||||||
|
return letters.map { String($0).uppercased() }.joined()
|
||||||
|
}
|
||||||
|
|
||||||
struct ImagePicker: UIViewControllerRepresentable {
|
struct ImagePicker: UIViewControllerRepresentable {
|
||||||
@Binding var image: UIImage?
|
@Binding var image: UIImage?
|
||||||
var allowsEditing: Bool = false
|
var allowsEditing: Bool = false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user