Skip to content

Commit

Permalink
refactor/#388 지각 꾸물이 뷰 분기 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
youz2me committed Sep 16, 2024
1 parent 1d3a774 commit 5374f6f
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -174,7 +193,7 @@ private extension PromiseViewController {

@objc
func finishMeetingButtonDidTap() {

viewModel.updatePromiseCompletion()
}

@objc
Expand Down
4 changes: 2 additions & 2 deletions KkuMulKum/Source/Promise/Tardy/View/TardyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class TardyView: BaseView {
backgroundColor = .white

addSubviews(
tardyPenaltyView,
titleLabel,
tardyEmptyView,
noTardyView,
tardyCollectionView,
finishMeetingButton
finishMeetingButton,
tardyPenaltyView
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
}

Expand All @@ -68,7 +138,7 @@ extension TardyViewController: UICollectionViewDataSource {
_ collectionView: UICollectionView,
numberOfItemsInSection section: Int
) -> Int {
return 0
return viewModel.tardyList.value.count
}

func collectionView(
Expand All @@ -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
}
}
32 changes: 32 additions & 0 deletions KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

import Foundation

enum TardyScreen {
case tardyEmptyView
case tardyListView
case noTardyView
}

class PromiseViewModel {


Expand All @@ -21,6 +27,9 @@ class PromiseViewModel {
let participantList = ObservablePattern<[Participant]>([])
let tardyList = ObservablePattern<[Comer]>([])

let isFinishSuccess = ObservablePattern<Bool?>(nil)
let errorMessage = ObservablePattern<String?>(nil)

var pageControlDirection = false

private let service: PromiseServiceProtocol
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)")
}
Expand Down

0 comments on commit 5374f6f

Please sign in to comment.