Skip to content

Commit

Permalink
fix/#388 약속 상세 네비게이션 바 이름 안뜨는 오류 해결, 약속 정보 수정 버튼 분기 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
youz2me committed Sep 15, 2024
1 parent 3ee91c4 commit cee7343
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,7 @@ class PromiseViewController: BaseViewController {
for: .valueChanged
)

promiseTardyViewController.tardyView.finishMeetingButton.addTarget(
self,
action: #selector(finishMeetingButtonDidTap),
for: .touchUpInside
)

promiseTardyViewController.arriveView.finishMeetingButton.addTarget(
promiseTardyViewController.rootView.finishMeetingButton.addTarget(
self,
action: #selector(finishMeetingButtonDidTap),
for: .touchUpInside
Expand Down Expand Up @@ -143,7 +137,7 @@ class PromiseViewController: BaseViewController {
private extension PromiseViewController {
func setupBinding() {
viewModel.promiseInfo.bindOnMain(with: self) { owner, info in
guard let isParticipant = info?.isParticipant else { return }
guard let info else { return }

let moreButton = UIBarButtonItem(
image: .imgMore.withRenderingMode(.alwaysOriginal),
Expand All @@ -152,7 +146,8 @@ private extension PromiseViewController {
action: #selector(owner.moreButtonDidTap)
)

owner.navigationController?.navigationItem.rightBarButtonItem = isParticipant ? moreButton : nil
owner.navigationController?.navigationItem.rightBarButtonItem = info.isParticipant ? moreButton : nil
owner.setupNavigationBarTitle(with: info.promiseName, isBorderHidden: true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PromiseInfoViewController: BaseViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

viewModel.fetchTardyInfo()
viewModel.fetchPromiseInfo()
viewModel.fetchPromiseParticipantList()
}
Expand Down Expand Up @@ -76,8 +77,7 @@ extension PromiseInfoViewController {
viewModel.promiseInfo.bindOnMain(with: self) { owner, info in
guard let info else { return }

owner.rootView.editButton.isHidden = !(info.isParticipant)

owner.rootView.editButton.isHidden = owner.viewModel.isEditButtonHidden()
owner.rootView.promiseNameLabel.setText(info.promiseName, style: .body01)
owner.rootView.locationContentLabel.setText(info.placeName, style: .body04)
owner.rootView.readyLevelContentLabel.setText(info.dressUpLevel, style: .body04)
Expand All @@ -90,25 +90,29 @@ extension PromiseInfoViewController {

switch dDay {
case 1...:
owner.rootView.dDayLabel.setText("D-\(dDay)", style: .body05, color: .gray5)
case 0:
owner.rootView.dDayLabel.setText("D-DAY", style: .body05, color: .mainorange)
case ..<0:
owner.rootView.dDayLabel.setText("D+\(-dDay)", style: .body05, color: .gray4)
owner.rootView.promiseImageView.image = .imgPromiseGray
owner.rootView.promiseNameLabel.textColor = .gray4
owner.rootView.locationInfoLabel.textColor = .gray4
owner.rootView.timeInfoLabel.textColor = .gray4
owner.rootView.readyLevelInfoLabel.textColor = .gray4
owner.rootView.penaltyLevelInfoLabel.textColor = .gray4
case 0:
owner.rootView.dDayLabel.setText("D-DAY", style: .body05, color: .mainorange)
case ..<0:
owner.rootView.dDayLabel.setText("D-\(dDay)", style: .body05, color: .gray5)
default:
break
}
}

viewModel.participants.bindOnMain(with: self) { owner, _ in
viewModel.participantList.bindOnMain(with: self) { owner, _ in
owner.rootView.participantCollectionView.reloadData()
}

viewModel.isPastDue.bindOnMain(with: self) { owner, _ in
owner.rootView.editButton.isHidden = owner.viewModel.isEditButtonHidden()
}
}

@objc
Expand Down Expand Up @@ -155,7 +159,7 @@ extension PromiseInfoViewController: UICollectionViewDataSource {
_ collectionView: UICollectionView,
numberOfItemsInSection section: Int
) -> Int {
return viewModel.participants.value.count
return viewModel.participantList.value.count
}

func collectionView(
Expand All @@ -169,7 +173,7 @@ extension PromiseInfoViewController: UICollectionViewDataSource {
return UICollectionViewCell()
}

let info = viewModel.participants.value[indexPath.row]
let info = viewModel.participantList.value[indexPath.row]

cell.userNameLabel.setText(info.name, style: .caption02, color: .gray6)
cell.profileImageView.kf.setImage(
Expand Down
26 changes: 24 additions & 2 deletions KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ class PromiseViewModel {

let promiseID: Int
let promiseInfo = ObservablePattern<PromiseInfoModel?>(nil)
let participants = ObservablePattern<[Participant]>([])
let isPastDue = ObservablePattern<Bool?>(nil)
let penalty = ObservablePattern<String?>(nil)
let dDay = ObservablePattern<Int?>(nil)
let participantList = ObservablePattern<[Participant]>([])
let tardyList = ObservablePattern<[Comer]>([])

private let service: PromiseServiceProtocol

Expand Down Expand Up @@ -50,6 +53,16 @@ private extension PromiseViewModel {
}

extension PromiseViewModel {
func isEditButtonHidden() -> Bool {
guard let isParticipant = promiseInfo.value?.isParticipant,
let isPastDue = isPastDue.value
else {
return false
}

return !(isParticipant && !isPastDue)
}

/// 약속 상세 정보 조회 API 구현 함수
func fetchPromiseInfo() {
Task {
Expand Down Expand Up @@ -90,7 +103,7 @@ extension PromiseViewModel {
return
}

participants.value = data.participants
participantList.value = data.participants
} catch {
print(">>>>> \(error.localizedDescription) : \(#function)")
}
Expand Down Expand Up @@ -184,6 +197,15 @@ extension PromiseViewModel {
print(">>>>> \(String(describing: result)) : \(#function)")
return
}

guard let data = result?.data else {
print(">>>>> \("데이터 없음") : \(#function)")
return
}

penalty.value = data.penalty
isPastDue.value = data.isPastDue
tardyList.value = data.lateComers
} catch {
print(">>>>> \(error.localizedDescription) : \(#function)")
}
Expand Down

0 comments on commit cee7343

Please sign in to comment.