diff --git a/ALUM/ALUM/Components/EditProfileImage.swift b/ALUM/ALUM/Components/EditProfileImage.swift index 31ee23f1..e041477c 100644 --- a/ALUM/ALUM/Components/EditProfileImage.swift +++ b/ALUM/ALUM/Components/EditProfileImage.swift @@ -47,8 +47,6 @@ struct EditProfileImage: View { }.onAppear(perform: { Task { /// Get user's current image - /// We cannot use the loading state of ProfileImage because - /// we are loading the image ourself to get a UIImage do { loading = true image = try await ImageService.shared.getImage(imageId: imageId) @@ -66,8 +64,13 @@ struct EditProfileImage: View { if loading { ProgressView() .frame(width: 112, height: 112) + } else if image != nil { + Image(uiImage: image!) + .resizable() + .frame(width: 112, height: 112) + .clipShape(Circle()) } else { - ProfileImage(image: $image, size: 112) + Image("DefaultProfileImage") } } .padding(20) diff --git a/ALUM/ALUM/Components/HorizontalMenteeCard.swift b/ALUM/ALUM/Components/HorizontalMenteeCard.swift index 7ada0c6b..13e924b2 100644 --- a/ALUM/ALUM/Components/HorizontalMenteeCard.swift +++ b/ALUM/ALUM/Components/HorizontalMenteeCard.swift @@ -11,7 +11,6 @@ struct HorizontalMenteeCard: View { var menteeId: String var school: String = "NHS" - @State var isEmpty = true @StateObject private var viewModel = MenteeProfileViewmodel() var body: some View { @@ -43,18 +42,8 @@ struct HorizontalMenteeCard: View { RoundedRectangle(cornerRadius: 12.0) .frame(width: 358, height: 118) .foregroundColor(Color("ALUM Primary Purple")) - if isEmpty { - Circle() - .frame(width: 85) - .foregroundColor(Color("NeutralGray1")) - .offset(x: -112.5) - } else { - Image(mentee.imageId) - .resizable() - .clipShape(Circle()) - .frame(width: 85, height: 85) - .offset(x: -112.5) - } + ProfileImage(imageId: mentee.imageId, size: 85) + .offset(x: -112.5) VStack { HStack { Text(mentee.name) diff --git a/ALUM/ALUM/Components/MentorCard.swift b/ALUM/ALUM/Components/MentorCard.swift index be379cfe..2e312acc 100644 --- a/ALUM/ALUM/Components/MentorCard.swift +++ b/ALUM/ALUM/Components/MentorCard.swift @@ -8,7 +8,6 @@ import SwiftUI struct MentorCard: View { - @State var isEmpty = false @State var uID: String = "" @StateObject private var viewModel = MentorProfileViewModel() @@ -36,18 +35,8 @@ struct MentorCard: View { RoundedRectangle(cornerRadius: 12.0) .frame(width: 358, height: 118) .foregroundColor(Color("ALUM Primary Purple")) - if isEmpty { - Circle() - .frame(width: 85, height: 85) - .foregroundColor(Color("NeutralGray1")) - .offset(x: -112.5) - } else { - Image("ALUMLogoBlue") - .resizable() - .clipShape(Circle()) - .frame(width: 85, height: 85) - .offset(x: -112.5) - } + ProfileImage(imageId: mentor.imageId, size: 85) + .offset(x: -112.5) VStack { HStack { Text(mentor.name) diff --git a/ALUM/ALUM/Components/ProfileImage.swift b/ALUM/ALUM/Components/ProfileImage.swift index 19741f28..7898c06d 100644 --- a/ALUM/ALUM/Components/ProfileImage.swift +++ b/ALUM/ALUM/Components/ProfileImage.swift @@ -8,41 +8,33 @@ import SwiftUI struct ProfileImage: View { + let imageId: String + let size: CGFloat @State var loading = false - @Binding var imageId: String? - @Binding var image: UIImage? - var size: CGFloat - - init(image: Binding = .constant(nil), imageId: Binding = .constant(nil), size: CGFloat = 100) { - _image = image - _imageId = imageId - self.size = size - } + @State var image: UIImage? var body: some View { Group { if loading { ProgressView() .frame(width: size, height: size) - } else if image != nil { - Image(uiImage: image!) - .resizable() - .frame(width: size, height: size) - .clipShape(Circle()) } else { - Image("DefaultProfileImage") + ( + image != nil ? Image(uiImage: image!) : Image("DefaultProfileImage") + ) + .resizable() + .clipShape(Circle()) + .frame(width: size, height: size) } }.onAppear(perform: { Task { - if imageId != nil { - do { - loading = true - image = try await ImageService.shared.getImage(imageId: imageId!) - loading = false - } catch { - /// User has no image - loading = false - } + do { + loading = true + image = try await ImageService.shared.getImage(imageId: imageId) + loading = false + } catch { + /// User has no image + loading = false } } }) @@ -51,8 +43,8 @@ struct ProfileImage: View { struct ProfileImage_Previews: PreviewProvider { static var previews: some View { - @State var imageId: String? = "64893922bc50c5db8870cc59" + @State var imageId = "64893922bc50c5db8870cc59" - return ProfileImage(imageId: $imageId, size: 100) + return ProfileImage(imageId: imageId, size: 100) } } diff --git a/ALUM/ALUM/Views/HomeScreen.swift b/ALUM/ALUM/Views/HomeScreen.swift index 123c4e68..c36ff465 100644 --- a/ALUM/ALUM/Views/HomeScreen.swift +++ b/ALUM/ALUM/Views/HomeScreen.swift @@ -56,10 +56,7 @@ struct HomeScreen: View { .padding(.bottom, 5) NavigationLink(destination: MenteeProfileScreen(uID: pairedMenteeId)) { - HorizontalMenteeCard( - menteeId: pairedMenteeId, - isEmpty: true - ) + HorizontalMenteeCard(menteeId: pairedMenteeId) .padding(.bottom, 28) } } @@ -79,7 +76,7 @@ struct HomeScreen: View { .padding(.bottom, 5) NavigationLink(destination: MentorProfileScreen(uID: pairedMentorId)) { - MentorCard(isEmpty: true, uID: pairedMentorId) + MentorCard(uID: pairedMentorId) .padding(.bottom, 28) } } diff --git a/ALUM/ALUM/Views/MenteeProfileScreen.swift b/ALUM/ALUM/Views/MenteeProfileScreen.swift index e148b8e3..d7f887db 100644 --- a/ALUM/ALUM/Views/MenteeProfileScreen.swift +++ b/ALUM/ALUM/Views/MenteeProfileScreen.swift @@ -36,9 +36,6 @@ struct MenteeProfileScreen: View { } var content: some View { - let mentee = viewModel.mentee! - - return GeometryReader { grr in VStack(spacing: 0) { ScrollView { @@ -95,11 +92,7 @@ extension MenteeProfileScreen { Circle() .frame(width: 135, height: 145) .foregroundColor(Color("ALUM White2")) - Image("ALUMLogoBlue") - .resizable() - .frame(width: 135, height: 135) - .clipShape(Circle()) - .scaledToFit() + ProfileImage(imageId: viewModel.mentee!.imageId, size: 135) } .padding(.top, 57) } @@ -159,7 +152,7 @@ extension MenteeProfileScreen { }) .customNavigationTitle("Mentor Profile") ) { - MentorCard(isEmpty: true, uID: viewModel.mentee!.mentorId ?? "") + MentorCard(uID: viewModel.mentee!.mentorId ?? "") .padding(.bottom, 10) } } diff --git a/ALUM/ALUM/Views/MentorProfileScreen.swift b/ALUM/ALUM/Views/MentorProfileScreen.swift index 810cf675..e429027b 100644 --- a/ALUM/ALUM/Views/MentorProfileScreen.swift +++ b/ALUM/ALUM/Views/MentorProfileScreen.swift @@ -114,11 +114,7 @@ extension MentorProfileScreen { Circle() .frame(width: 135, height: 145) .foregroundColor(Color("ALUM White2")) - Image("ALUMLogoBlue") - .resizable() - .frame(width: 135, height: 135) - .clipShape(Circle()) - .scaledToFit() + ProfileImage(imageId: viewModel.mentor!.imageId, size: 135) } .padding(.top, 57) } diff --git a/ALUM/ALUM/Views/SessionDetailsScreen.swift b/ALUM/ALUM/Views/SessionDetailsScreen.swift index d6f33ad5..b0684336 100644 --- a/ALUM/ALUM/Views/SessionDetailsScreen.swift +++ b/ALUM/ALUM/Views/SessionDetailsScreen.swift @@ -306,10 +306,7 @@ extension SessionDetailsScreen { uID: session.menteeId ).customNavigationTitle("Mentee Profile") ) { - HorizontalMenteeCard( - menteeId: session.menteeId, - isEmpty: true - ) + HorizontalMenteeCard(menteeId: session.menteeId) .padding(.bottom, 28) } dateTimeDisplaySection @@ -371,7 +368,7 @@ extension SessionDetailsScreen { MentorProfileScreen(uID: session.mentorId) .customNavigationTitle("Mentor Profile") ) { - MentorCard(isEmpty: true, uID: session.mentorId) + MentorCard(uID: session.mentorId) .padding(.bottom, 28) } dateTimeDisplaySection