Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ public final class StudentInfoView: UIView {
}
}
}
extension StudentInfoView {
public func updateProfileImage(image: UIImage) {
profileImageView.image = image
}
}
56 changes: 45 additions & 11 deletions Projects/Presentation/Sources/MyPage/MyPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,26 @@ public final class MyPageViewController: BaseViewController<MyPageViewModel> {
}
private let contentView = UIView()
private let studentInfoView = StudentInfoView()
// private let editButton = UIButton(type: .system).then {
// $0.setJobisText("μˆ˜μ •", font: .subHeadLine, color: .Primary.blue20)
// }
private let editButton = UIButton(type: .system).then {
$0.setJobisText("μˆ˜μ •", font: .subHeadLine, color: .Primary.blue20)
}
private let reviewNavigateStackView = ReviewNavigateStackView()
private let notificationSettingSectionView = NotificationSettingSectionView()
private let accountSectionView = AccountSectionView()
private let bugSectionView = BugSectionView()
private let helpSectionView = HelpSectionView()
private let selectedImage = PublishRelay<UploadFileModel>()
private let picker = UIImagePickerController()
private let logoutPublisher = PublishRelay<Void>()
private let withdrawalPublisher = PublishRelay<Void>()
private let changedImageURL = PublishRelay<String>()

public override func addView() {
self.view.addSubview(scrollView)
self.scrollView.addSubview(contentView)
[
studentInfoView,
// editButton,
editButton,
reviewNavigateStackView,
notificationSettingSectionView,
helpSectionView,
Expand All @@ -55,10 +58,10 @@ public final class MyPageViewController: BaseViewController<MyPageViewModel> {
$0.leading.trailing.equalToSuperview()
}

// editButton.snp.makeConstraints {
// $0.centerY.equalTo(studentInfoView)
// $0.trailing.equalToSuperview().offset(-28)
// }
editButton.snp.makeConstraints {
$0.centerY.equalTo(studentInfoView)
$0.trailing.equalToSuperview().offset(-28)
}

reviewNavigateStackView.snp.updateConstraints {
$0.leading.trailing.equalToSuperview().inset(24)
Expand Down Expand Up @@ -90,15 +93,18 @@ public final class MyPageViewController: BaseViewController<MyPageViewModel> {

public override func bind() {
let input = MyPageViewModel.Input(
viewAppear: self.viewDidLoadPublisher,
viewAppear: viewWillAppearPublisher,
reviewNavigate: reviewNavigateStackView.reviewNavigateButtonDidTap,
notificationSettingSectionDidTap: notificationSettingSectionView.getSelectedItem(type: .notificationSetting),
selectedImage: selectedImage,
notificationSettingSectionDidTap: notificationSettingSectionView.getSelectedItem(type:
.notificationSetting),
helpSectionDidTap: helpSectionView.getSelectedItem(type: .announcement),
bugReportSectionDidTap: bugSectionView.getSelectedItem(type: .reportBug),
// bugReportListSectionDidTap: bugSectionView.getSelectedItem(type: .bugList),
changePasswordSectionDidTap: accountSectionView.getSelectedItem(type: .changePassword),
logoutPublisher: logoutPublisher,
withdrawalPublisher: withdrawalPublisher
withdrawalPublisher: withdrawalPublisher,
changedImageURL: changedImageURL
)

input.changePasswordSectionDidTap.asObservable()
Expand Down Expand Up @@ -126,6 +132,7 @@ public final class MyPageViewController: BaseViewController<MyPageViewModel> {
}

public override func configureViewController() {
self.picker.delegate = self
self.viewWillAppearPublisher.asObservable()
.subscribe(onNext: { [weak self] in
self?.showTabbar()
Expand Down Expand Up @@ -157,9 +164,36 @@ public final class MyPageViewController: BaseViewController<MyPageViewModel> {
.show()
})
.disposed(by: disposeBag)

self.editButton.rx.tap
.subscribe(onNext: { [weak self] in
self?.openLibrary()
})
.disposed(by: disposeBag)
}

public override func configureNavigation() {
self.setLargeTitle(title: "λ§ˆμ΄νŽ˜μ΄μ§€")
}
}

extension MyPageViewController: UIImagePickerControllerDelegate {
func openLibrary() {
picker.sourceType = .photoLibrary
present(picker, animated: true, completion: nil)
}
}

extension MyPageViewController: UINavigationControllerDelegate {
public func imagePickerController(
_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]
) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
guard let imageData = image.pngData() else { return }
self.studentInfoView.updateProfileImage(image: image)
self.selectedImage.accept(.init(file: imageData, fileName: "profile.png"))
dismiss(animated: true, completion: nil)
}
}
}
44 changes: 38 additions & 6 deletions Projects/Presentation/Sources/MyPage/MyPageViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,27 @@ public final class MyPageViewModel: BaseViewModel, Stepper {
public struct Input {
let viewAppear: PublishRelay<Void>
let reviewNavigate: PublishRelay<Int>
let selectedImage: PublishRelay<UploadFileModel>
let notificationSettingSectionDidTap: Observable<IndexPath>
let helpSectionDidTap: Observable<IndexPath>
let bugReportSectionDidTap: Observable<IndexPath>
// let bugReportListSectionDidTap: Observable<IndexPath>
// let bugReportListSectionDidTap: Observable<IndexPath>
let changePasswordSectionDidTap: Observable<IndexPath>
let logoutPublisher: PublishRelay<Void>
let withdrawalPublisher: PublishRelay<Void>
let changedImageURL: PublishRelay<String>
}

public struct Output {
let studentInfo: PublishRelay<StudentInfoEntity>
let writableReviewList: BehaviorRelay<[WritableReviewCompanyEntity]>
let changedImageURL: PublishRelay<String>
}

public func transform(_ input: Input) -> Output {
let studentInfo = PublishRelay<StudentInfoEntity>()
let writableReviewList = BehaviorRelay<[WritableReviewCompanyEntity]>(value: [])
let changedImageURL = PublishRelay<String>()

input.viewAppear.asObservable()
.flatMap { self.fetchStudentInfoUseCase.execute() }
Expand All @@ -70,6 +74,33 @@ public final class MyPageViewModel: BaseViewModel, Stepper {
.bind(to: steps)
.disposed(by: disposeBag)

input.selectedImage
.flatMapLatest { [weak self] file -> Observable<String?> in
guard let self = self else { return .empty() }

return self.fetchPresignedURLUseCase.execute(
req: .init(files: [.init(fileName: file.fileName)])
)
.asObservable()
.flatMap { presignedURLs -> Observable<String?> in
guard let url = presignedURLs.first else { return .empty() }

return Observable.zip(
self.uploadImageToS3UseCase.execute(
presignedURL: url.presignedUrl,
data: file.file
)
.asObservable(),
self.changeProfileImageUseCase.execute(url: url.filePath)
.asObservable()
)
.map { _ in "" }
}
}
.map { _ in "" }
.bind(to: changedImageURL)
.disposed(by: disposeBag)

input.notificationSettingSectionDidTap.asObservable()
.map { _ in MyPageStep.notificationSettingIsRequired }
.bind(to: steps)
Expand Down Expand Up @@ -108,14 +139,15 @@ public final class MyPageViewModel: BaseViewModel, Stepper {
.bind(to: steps)
.disposed(by: disposeBag)

// input.bugReportListSectionDidTap.asObservable()
// .map { _ in MyPageStep.bugReportListIsRequired }
// .bind(to: steps)
// .disposed(by: disposeBag)
// input.bugReportListSectionDidTap.asObservable()
// .map { _ in MyPageStep.bugReportListIsRequired }
// .bind(to: steps)
// .disposed(by: disposeBag)

return Output(
studentInfo: studentInfo,
writableReviewList: writableReviewList
writableReviewList: writableReviewList,
changedImageURL: changedImageURL
)
}
}