Skip to content

Commit

Permalink
implement removing profile image
Browse files Browse the repository at this point in the history
  • Loading branch information
petabite committed Jun 14, 2023
1 parent 3197b63 commit e3011e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 11 additions & 4 deletions ALUM/ALUM/Components/EditProfileImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ 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
/// 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)
loading = false
} catch {
CurrentUserModel.shared.showInternalError.toggle()
/// User has no image (ie. imageId is "" or invalid image id)
loading = false
}
}
})
Expand All @@ -64,7 +66,7 @@ struct EditProfileImage: View {
if loading {
ProgressView()
.frame(width: 112, height: 112)
} else {
} else {
ProfileImage(image: $image, size: 112)
}
}
Expand All @@ -73,7 +75,11 @@ struct EditProfileImage: View {

func handleDone() {
Task {
guard let selectedImage = image else { return }
guard let selectedImage = image else {
/// no image selected (or image was removed)
showChooseSheet = false
return
}
do {
/// Upload image
uploading = true
Expand Down Expand Up @@ -140,6 +146,7 @@ struct EditProfileImage: View {

Button(action: {
image = nil
imageId = ""
}, label: {
HStack {
Image("TrashIcon")
Expand Down
3 changes: 2 additions & 1 deletion ALUM/ALUM/Components/ProfileImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ struct ProfileImage: View {
image = try await ImageService.shared.getImage(imageId: imageId!)
loading = false
} catch {
CurrentUserModel.shared.showInternalError.toggle()
/// User has no image
loading = false
}
}
}
Expand Down

0 comments on commit e3011e7

Please sign in to comment.