Skip to content

Commit

Permalink
feat/#358 준비 정보 수정 플로우 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaybei committed Sep 3, 2024
1 parent bae56e1 commit 62099b0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,20 @@ extension ReadyStatusViewController {
guard let _ = viewModel.promiseInfo.value?.promiseName else { return }
guard let readyStatusInfo = viewModel.myReadyStatus.value else { return }

let setReadyInfoViewController = SetReadyInfoViewController(
viewModel: SetReadyInfoViewModel(
promiseID: viewModel.promiseID,
promiseTime: readyStatusInfo.promiseTime,
promiseName: viewModel.promiseInfo.value?.promiseName ?? "",
service: PromiseService()
)
let setReadyInfoViewModel = SetReadyInfoViewModel(
promiseID: viewModel.promiseID,
promiseTime: readyStatusInfo.promiseTime,
promiseName: viewModel.promiseInfo.value?.promiseName ?? "",
service: PromiseService()
)

setReadyInfoViewModel.storedReadyHour = (readyStatusInfo.preparationTime ?? 0) / 60
setReadyInfoViewModel.storedReadyMinute = (readyStatusInfo.preparationTime ?? 0) % 60
setReadyInfoViewModel.storedMoveHour = (readyStatusInfo.travelTime ?? 0) / 60
setReadyInfoViewModel.storedMoveMinute = (readyStatusInfo.travelTime ?? 0) % 60

let setReadyInfoViewController = SetReadyInfoViewController(viewModel: setReadyInfoViewModel)

navigationController?.pushViewController(
setReadyInfoViewController,
animated: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ final class SetReadyInfoViewController: BaseViewController {

// MARK: - LifeCycle

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

navigationController?.isNavigationBarHidden = false
}

override func loadView() {
self.view = rootView
}
Expand All @@ -47,8 +41,15 @@ final class SetReadyInfoViewController: BaseViewController {
setupNavigationBarBackButton()
setupNavigationBarTitle(with: "준비 정보 입력하기")

bindViewModel()
setupBinding()
setupTapGesture()
setupTextField()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

navigationController?.isNavigationBarHidden = false
}

override func setupDelegate() {
Expand Down Expand Up @@ -121,10 +122,13 @@ extension SetReadyInfoViewController: UITextFieldDelegate {

func textFieldDidEndEditing(_ textField: UITextField) {
textField.layer.borderColor = UIColor.gray3.cgColor
viewModel.updateTime(
textField: textField.accessibilityIdentifier ?? "",
time: textField.text ?? ""
)

if let text = textField.text, !text.isEmpty {
viewModel.updateTime(
textField: textField.accessibilityIdentifier ?? "",
time: textField.text ?? ""
)
}
}

func textField(
Expand All @@ -142,6 +146,20 @@ extension SetReadyInfoViewController: UITextFieldDelegate {
// MARK: - Function

private extension SetReadyInfoViewController {
func setupTextField() {
/// 저장된 준비 시간이 0이 아니면 텍스트 필드에 설정
if viewModel.storedReadyHour != 0 || viewModel.storedReadyMinute != 0 {
rootView.readyHourTextField.text = String(viewModel.storedReadyHour)
rootView.readyMinuteTextField.text = String(viewModel.storedReadyMinute)
}

/// 저장된 이동 시간이 0이 아니면 텍스트 필드에 설정
if viewModel.storedMoveHour != 0 || viewModel.storedMoveMinute != 0 {
rootView.moveHourTextField.text = String(viewModel.storedMoveHour)
rootView.moveMinuteTextField.text = String(viewModel.storedMoveMinute)
}
}

func setTextFieldDelegate() {
let textFields: [(UITextField, String)] = [
(rootView.readyHourTextField, "readyHour"),
Expand All @@ -164,7 +182,7 @@ private extension SetReadyInfoViewController {

// MARK: - Data Bind

func bindViewModel() {
func setupBinding() {
viewModel.readyHour.bind { [weak self] readyHour in
self?.rootView.readyHourTextField.text = readyHour
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ final class SetReadyInfoViewModel {

let isValid = ObservablePattern<Bool>(false)
let errMessage = ObservablePattern<String>("")

let readyHour = ObservablePattern<String>("")
let readyMinute = ObservablePattern<String>("")
let moveHour = ObservablePattern<String>("")
let moveMinute = ObservablePattern<String>("")
let isSucceedToSave = ObservablePattern<Bool>(false)

var readyHour = ObservablePattern<String>("")
var readyMinute = ObservablePattern<String>("")
var moveHour = ObservablePattern<String>("")
var moveMinute = ObservablePattern<String>("")

var preparationTime = ObservablePattern<Int>(0)
var travelTime = ObservablePattern<Int>(0)

var storedReadyHour: Int = 0
var storedReadyMinute: Int = 0
var storedMoveHour: Int = 0
var storedMoveMinute: Int = 0

var readyTime: Int = 0
var moveTime: Int = 0

Expand Down Expand Up @@ -52,10 +60,10 @@ final class SetReadyInfoViewModel {
}

private func calculateTimes() {
let readyHours = Int(readyHour.value) ?? 0
let readyMinutes = Int(readyMinute.value) ?? 0
let moveHours = Int(moveHour.value) ?? 0
let moveMinutes = Int(moveMinute.value) ?? 0
let readyHours = Int(readyHour.value) ?? storedReadyHour
let readyMinutes = Int(readyMinute.value) ?? storedReadyMinute
let moveHours = Int(moveHour.value) ?? storedMoveHour
let moveMinutes = Int(moveMinute.value) ?? storedMoveMinute

readyTime = readyHours * 60 + readyMinutes
moveTime = moveHours * 60 + moveMinutes
Expand Down

0 comments on commit 62099b0

Please sign in to comment.