-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/7 fetch user profile #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コメントしましたー!
func setUserProfileImage(imageData: Data) { | ||
DispatchQueue.main.async { | ||
self.editProfileButton.isEnabled = false | ||
self.profileImageView.image = UIImage(data: imageData)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.profileImageView.image = UIImage(data: imageData)!
の右辺は
UIImage(data: imageData) ?? UIImage()
が良さそうです
editProfileButton.isEnabled = false | ||
editProfileButton.layer.cornerRadius = 10.0 | ||
profileImageView.layer.cornerRadius = profileImageView.frame.height / 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここの3行はそれぞれの変数に対して関数で切り分けたほうがいいと思います!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
レビューしました!
self.firestore.collection("message/v1/users").document("y783WJnXJqDfDED0nBvK").getDocument { (document, error) in | ||
if let error = error { | ||
print("Error: \(error.localizedDescription)") | ||
return | ||
} | ||
|
||
guard let document = document, document.exists else { | ||
print("The document doesn't exist.") | ||
return | ||
} | ||
|
||
do { | ||
let user = try Firestore.Decoder().decode(User.self, from: document.data()!) | ||
self.presenter.successFetchUser(user: user) | ||
self.downloadProfile(downLoadURL: user.profileImageURL ?? "") | ||
} catch { | ||
fatalError() | ||
} | ||
|
||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここはlistenerの方がuserのdisplayNameやprofileImageURLを変えた時に更新しなくて良くなるのでいいと思います!
それとusersのdocumentIDはauthのuidと一緒なので
guard let uid = Auth.auth().currentUser?.uid else { return }
let userReference = Firestore.firestore()collection("message/v1/users").document(uid)
listner = userReference.addSnapshotListener { (snapshot,error) in
エラーじゃない場合はpresenterのsuccessFetchUserを呼ぶ
}
っていう感じになると思います
private func downloadProfile(downLoadURL: String) { | ||
let httpsReference = Storage.storage().reference(forURL: downLoadURL) | ||
httpsReference.getData(maxSize: 1 * 512 * 512) { data, error in | ||
if let error = error { | ||
print(error.localizedDescription) | ||
return | ||
} | ||
|
||
guard let data = data else { | ||
return | ||
} | ||
|
||
self.presenter.successFetchImageData(imageData: data) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userを取ってくる処理だけしてimageViewにuserのプロフィール画像を入れる処理はNukeに任せたほうがいいです!
import Nuke
して
let options = ImageLoadingOptions(placeholder: デフォルトの画像, failureImage: 失敗した時の画像)
loadImage(with: userのprofileImageURL, options: options, into: profileImageView, progress: nil, completion: nil)
こんな感じでしょうか
Nukeについてはoptionsとかも色々あるので調べた方が良いかもです!
var userName = "" | ||
var profileImage = UIImage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserProfileViewControllerからEditProfileViewControllerにへの値渡しはViewBuilderを介して行った方が良いです!
UserProfileViewControllerで
func presentEditProfileViewController(user: User) {
let editProfileVC = EditProfileViewBuilder.create(user: user)
let navigationController = UINavigationController(rootViewController: editProfileVC)
navigationController.modalPresentationStyle = .fullScreen
present(navigationController, animated: true, completion: nil)
}
こんな感じになるようにして
struct EditProfileViewBuilder {
static func create(user: User) -> UIViewController {
guard let EditProfileViewController = EditProfileViewController.loadFromStoryboard() as? EditProfileViewController else {
fatalError("fatal: Failed to initialize the EditProfileViewController")
}
let model = EditProfileModel()
let presenter = EditProfileViewPresenter(model: model, user: user)
EditProfileViewController.inject(with: presenter)
return EditProfileViewController
}
}
EditProfileViewBuilderはこんな感じでしょうか
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
値の受け渡し、もう少し調べてから頑張ります。。
@@ -42,10 +43,12 @@ final class EditProfileViewController: UIViewController { | |||
} | |||
|
|||
func setupNameTextField() { | |||
self.nameTextField.text = self.userName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
presenterにuserを渡すことになるので
nameTextField.text = presenter.user.displayName になります!
self.nameTextField.addBorderBottom(borderWidth: 1.0, color: .gray) | ||
} | ||
|
||
func setupImageView() { | ||
self.imageView.image = self.profileImage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここもuserのprofileImageURLを使ってnukeでimageViewの画像を変えたほうがいいです!
それとprofileImageの保存は |
概要
• Firebaseから名前と画像を取得して表示する処理を追加
レビュー観点
レビューレベル
Lv0: まったく見ないでAcceptするLv1: ぱっとみて違和感がないかチェックしてAcceptする
Lv2: 仕様レベルまで理解して、仕様通りに動くかある程度検証してAcceptするLv3: 実際に環境で動作確認したうえでAcceptするスクリーンショット
備考