From c077007dafcfe621ce458bb34c09ff8ae97d1dc3 Mon Sep 17 00:00:00 2001 From: IvanStepanok Date: Fri, 14 Feb 2025 17:29:41 +0200 Subject: [PATCH] fix: address feedback --- .../Presentation/EditProfile/EditProfileViewModel.swift | 9 +++++---- Profile/Profile/Presentation/Profile/ProfileView.swift | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Profile/Profile/Presentation/EditProfile/EditProfileViewModel.swift b/Profile/Profile/Presentation/EditProfile/EditProfileViewModel.swift index 62da0693..96a8516f 100644 --- a/Profile/Profile/Presentation/EditProfile/EditProfileViewModel.swift +++ b/Profile/Profile/Presentation/EditProfile/EditProfileViewModel.swift @@ -28,6 +28,7 @@ public class EditProfileViewModel: ObservableObject { var profileDidEdit: (((UserProfile?, UIImage?)) -> Void)? var oldAvatar: UIImage? + private let minimumFullAccountAge = 13 private let currentYear = Calendar.current.component(.year, from: Date()) public let profileTypes: [ProfileType] = [.full, .limited] private var years: [PickerFields.Option] = [] @@ -83,7 +84,7 @@ public class EditProfileViewModel: ObservableObject { guard let year = yearsConfiguration.text != "" ? Int(yearsConfiguration.text) : userModel.yearOfBirth else { return false } - if currentYear - year < 13 { + if currentYear - year < minimumFullAccountAge { return false } return profileChanges.profileType == .full @@ -173,7 +174,7 @@ public class EditProfileViewModel: ObservableObject { } else { yearOfBirth = userModel.yearOfBirth } - if yearOfBirth == 0 || currentYear - yearOfBirth < 13 { + if yearOfBirth == 0 || currentYear - yearOfBirth < minimumFullAccountAge { alertMessage = ProfileLocalization.Edit.tooYongUser } else { profileChanges.profileType.toggle() @@ -185,7 +186,7 @@ public class EditProfileViewModel: ObservableObject { func checkProfileType() { if yearsConfiguration.text != "" { let yearOfBirth = yearsConfiguration.text - if currentYear - (Int(yearOfBirth) ?? 0) < 13 { + if currentYear - (Int(yearOfBirth) ?? 0) < minimumFullAccountAge { profileChanges.profileType = .limited isYongUser = true } else { @@ -194,7 +195,7 @@ public class EditProfileViewModel: ObservableObject { } } } else { - if (currentYear - userModel.yearOfBirth) < 13 { + if (currentYear - userModel.yearOfBirth) < minimumFullAccountAge { profileChanges.profileType = .limited isYongUser = true } else { diff --git a/Profile/Profile/Presentation/Profile/ProfileView.swift b/Profile/Profile/Presentation/Profile/ProfileView.swift index c61ddf55..1691afc3 100644 --- a/Profile/Profile/Presentation/Profile/ProfileView.swift +++ b/Profile/Profile/Presentation/Profile/ProfileView.swift @@ -213,9 +213,12 @@ struct ProfileView_Previews: PreviewProvider { struct UserAvatar: View { private var url: URL? private var borderColor: Color + + private let defaultAvatarKeyword = "default" + @Binding private var image: UIImage? init(url: String, image: Binding, borderColor: Color = Theme.Colors.avatarStroke) { - if url.contains("default") { + if url.contains(defaultAvatarKeyword) { self.url = nil } else if let rightUrl = URL(string: url) { self.url = rightUrl