Skip to content

Commit

Permalink
refactor/#277 모임 생성 binding 코드 잘못된 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
youz2me committed Aug 8, 2024
1 parent b5219d6 commit f14a61d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ private extension CreateMeetingViewController {
func setupBinding() {
viewModel.inviteCodeState.bind(with: self) { owner, state in
switch state {
case .empty, .invalid:
owner.rootView.presentButton.isEnabled = false
case .valid:
owner.rootView.presentButton.isEnabled = true
case .empty, .invalid:
owner.rootView.presentButton.isEnabled = false
}
owner.viewModel.characterCount.bind(with: self) { owner, count in
owner.rootView.characterLabel.text = count
}
}

viewModel.characterCount.bind(with: self) { owner, count in
owner.rootView.characterLabel.text = "\(count)/10"
}
}

Expand All @@ -121,9 +121,7 @@ private extension CreateMeetingViewController {
viewModel.createMeeting(name: viewModel.meetingName.value)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
inviteCodePopUpViewController.rootView.setInvitationCodeText(
self.viewModel.inviteCode.value
)
inviteCodePopUpViewController.rootView.setInvitationCodeText(self.viewModel.inviteCode.value)

self.present(inviteCodePopUpViewController, animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class CreateMeetingViewModel {

// MARK: Property

let isNextButtonEnabled = ObservablePattern<Bool>(false)
let meetingName = ObservablePattern<String>("")
let inviteCode = ObservablePattern<String>("")
let characterCount = ObservablePattern<String>("0/10")
Expand All @@ -43,17 +42,15 @@ class CreateMeetingViewModel {
extension CreateMeetingViewModel {
func validateName(_ name: String) {
meetingName.value = name
characterCount.value = "\(name.count)/10"
characterCount.value = String(name.count)

if name.isEmpty {
switch name.count {
case 0:
inviteCodeState.value = .empty
isNextButtonEnabled.value = false
} else if name.count > 10 {
inviteCodeState.value = .invalid
isNextButtonEnabled.value = false
} else {
case 1...10:
inviteCodeState.value = .valid
isNextButtonEnabled.value = true
default:
inviteCodeState.value = .invalid
}
}

Expand Down

0 comments on commit f14a61d

Please sign in to comment.