From 5374f6ffe7d14f0ccf8103c844494cb0391d598e Mon Sep 17 00:00:00 2001 From: youz2me Date: Tue, 17 Sep 2024 02:25:32 +0900 Subject: [PATCH] =?UTF-8?q?refactor/#388=20=EC=A7=80=EA=B0=81=20=EA=BE=B8?= =?UTF-8?q?=EB=AC=BC=EC=9D=B4=20=EB=B7=B0=20=EB=B6=84=EA=B8=B0=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PromiseViewController.swift | 25 +++++- .../Source/Promise/Tardy/View/TardyView.swift | 4 +- .../ViewController/TardyViewController.swift | 79 ++++++++++++++++++- .../Promise/ViewModel/PromiseViewModel.swift | 32 ++++++++ 4 files changed, 134 insertions(+), 6 deletions(-) diff --git a/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift b/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift index 901a206..0b34c01 100644 --- a/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift +++ b/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift @@ -87,8 +87,7 @@ class PromiseViewController: BaseViewController { promiseSegmentedControl.snp.makeConstraints { $0.top.equalTo(view.safeAreaLayoutGuide) $0.leading.trailing.equalToSuperview().inset(-6) - $0.height.equalTo(Screen.height(60) - ) + $0.height.equalTo(Screen.height(60)) } promisePageViewController.view.snp.makeConstraints { @@ -164,6 +163,26 @@ private extension PromiseViewController { owner.promiseViewControllerList[index] ], direction: direction, animated: false) } + + viewModel.isFinishSuccess.bindOnMain(with: self) { owner, isSuccess in + guard let isSuccess = isSuccess else { return } + + if isSuccess { + self.navigationController?.popViewController(animated: true) + + if let viewController = self.navigationController?.viewControllers.last { + let toast = Toast() + toast.show(message: "약속 마치기 성공!", view: viewController.view, position: .bottom, inset: 100) + } + } + } + + viewModel.errorMessage.bindOnMain(with: self) { owner, message in + let toast = Toast() + guard let message = message else { return } + + toast.show(message: message, view: owner.view, position: .bottom, inset: 100) + } } @objc @@ -174,7 +193,7 @@ private extension PromiseViewController { @objc func finishMeetingButtonDidTap() { - + viewModel.updatePromiseCompletion() } @objc diff --git a/KkuMulKum/Source/Promise/Tardy/View/TardyView.swift b/KkuMulKum/Source/Promise/Tardy/View/TardyView.swift index 4c7ed84..8c20583 100644 --- a/KkuMulKum/Source/Promise/Tardy/View/TardyView.swift +++ b/KkuMulKum/Source/Promise/Tardy/View/TardyView.swift @@ -53,12 +53,12 @@ class TardyView: BaseView { backgroundColor = .white addSubviews( - tardyPenaltyView, titleLabel, tardyEmptyView, noTardyView, tardyCollectionView, - finishMeetingButton + finishMeetingButton, + tardyPenaltyView ) } diff --git a/KkuMulKum/Source/Promise/Tardy/ViewController/TardyViewController.swift b/KkuMulKum/Source/Promise/Tardy/ViewController/TardyViewController.swift index cdcb74c..e484c27 100644 --- a/KkuMulKum/Source/Promise/Tardy/ViewController/TardyViewController.swift +++ b/KkuMulKum/Source/Promise/Tardy/ViewController/TardyViewController.swift @@ -57,7 +57,77 @@ class TardyViewController: BaseViewController { private extension TardyViewController { func setupBinding() { + viewModel.penalty.bindOnMain(with: self) { owner, penalty in + owner.rootView.tardyPenaltyView.contentLabel.text = penalty + } + + viewModel.isPastDue.bindOnMain(with: self) { owner, isPastDue in + switch owner.viewModel.showTardyScreen() { + case .tardyEmptyView: + owner.rootView.do { + $0.finishMeetingButton.isEnabled = false + $0.tardyEmptyView.isHidden = false + $0.titleLabel.isHidden = false + $0.tardyPenaltyView.isHidden = false + $0.noTardyView.isHidden = true + $0.tardyCollectionView.isHidden = true + } + case .tardyListView: + owner.rootView.do { + $0.finishMeetingButton.isEnabled = true + $0.titleLabel.isHidden = false + $0.tardyPenaltyView.isHidden = false + $0.tardyCollectionView.isHidden = false + $0.tardyEmptyView.isHidden = true + $0.noTardyView.isHidden = true + + owner.rootView.tardyCollectionView.reloadData() + } + case .noTardyView: + owner.rootView.do { + $0.finishMeetingButton.isEnabled = true + $0.noTardyView.isHidden = false + $0.tardyEmptyView.isHidden = true + $0.titleLabel.isHidden = true + $0.tardyPenaltyView.isHidden = true + $0.tardyCollectionView.isHidden = true + } + } + } + viewModel.tardyList.bindOnMain(with: self) { owner, tardyList in + switch owner.viewModel.showTardyScreen() { + case .tardyEmptyView: + owner.rootView.do { + $0.finishMeetingButton.isEnabled = false + $0.tardyEmptyView.isHidden = false + $0.titleLabel.isHidden = false + $0.tardyPenaltyView.isHidden = false + $0.noTardyView.isHidden = true + $0.tardyCollectionView.isHidden = true + } + case .tardyListView: + owner.rootView.do { + $0.finishMeetingButton.isEnabled = true + $0.titleLabel.isHidden = false + $0.tardyPenaltyView.isHidden = false + $0.tardyCollectionView.isHidden = false + $0.tardyEmptyView.isHidden = true + $0.noTardyView.isHidden = true + + owner.rootView.tardyCollectionView.reloadData() + } + case .noTardyView: + owner.rootView.do { + $0.finishMeetingButton.isEnabled = true + $0.noTardyView.isHidden = false + $0.tardyEmptyView.isHidden = true + $0.titleLabel.isHidden = true + $0.tardyPenaltyView.isHidden = true + $0.tardyCollectionView.isHidden = true + } + } + } } } @@ -68,7 +138,7 @@ extension TardyViewController: UICollectionViewDataSource { _ collectionView: UICollectionView, numberOfItemsInSection section: Int ) -> Int { - return 0 + return viewModel.tardyList.value.count } func collectionView( @@ -82,6 +152,13 @@ extension TardyViewController: UICollectionViewDataSource { return UICollectionViewCell() } + guard let tardyName = viewModel.tardyList.value[indexPath.row].name else { + return cell + } + + cell.nameLabel.setText(tardyName, style: .body06, color: .gray6) + cell.profileImageView.kf.setImage(with: URL(string: viewModel.tardyList.value[indexPath.row].profileImageURL ?? ""), placeholder: UIImage.imgProfile) + return cell } } diff --git a/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift b/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift index 7d913df..30852d2 100644 --- a/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift +++ b/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift @@ -7,6 +7,12 @@ import Foundation +enum TardyScreen { + case tardyEmptyView + case tardyListView + case noTardyView +} + class PromiseViewModel { @@ -21,6 +27,9 @@ class PromiseViewModel { let participantList = ObservablePattern<[Participant]>([]) let tardyList = ObservablePattern<[Comer]>([]) + let isFinishSuccess = ObservablePattern(nil) + let errorMessage = ObservablePattern(nil) + var pageControlDirection = false private let service: PromiseServiceProtocol @@ -66,6 +75,23 @@ extension PromiseViewModel { return !(isParticipant && !isPastDue) } + func showTardyScreen() -> TardyScreen { + guard let isPastDue = isPastDue.value else { return .tardyEmptyView } + let hasTardy = !tardyList.value.isEmpty + + if !isPastDue { + return .tardyEmptyView + } + else if isPastDue && hasTardy { + return .tardyListView + } + else if isPastDue && !hasTardy { + return .noTardyView + } + + return .tardyEmptyView + } + /// 약속 상세 정보 조회 API 구현 함수 func fetchPromiseInfo() { Task { @@ -224,9 +250,15 @@ extension PromiseViewModel { guard let success = result?.success, success == true else { + guard let message = result?.error?.message else { return } + + errorMessage.value = message + print(">>>>> \(String(describing: result)) : \(#function)") return } + + isFinishSuccess.value = success } catch { print(">>>>> \(error.localizedDescription) : \(#function)") }