Skip to content

Commit

Permalink
Merge pull request #48 from jeongju9216/feature/change-new-goal-style
Browse files Browse the repository at this point in the history
NewGoalViewController 수정
  • Loading branch information
jeongju9216 authored Jun 30, 2023
2 parents df0469b + 2a414f9 commit 87cbe48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,18 @@ final class GoalListViewController: UIViewController {

//MARK: - Methods
@objc private func goGoalVC() {
let goalVC = NewGoalViewController.instantiate
navigationController?.pushViewController(goalVC, animated: true)
if let goalVC = NewGoalViewController.instantiate as? NewGoalViewController {
goalVC.newGoalViewControllerDelegate = self
present(goalVC, animated: true)
}
}

@objc private func showInfoVC() {
let infoVC = InfoViewController()
present(infoVC, animated: true)
}

private func goThreeDayVC(goal: Goal) {
func goThreeDayVC(goal: Goal) {
guard let threeDayVC = ThreeDayViewController.instantiate as? ThreeDayViewController else {
return
}
Expand Down Expand Up @@ -188,3 +190,8 @@ extension GoalListViewController: UICollectionViewDataSource {
return headerCell
}
}

//MARK: - NewGaolViewControllerDelegate
extension GoalListViewController: NewGoalViewControllerDelegate {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import UIKit

protocol NewGoalViewControllerDelegate: AnyObject {
func goThreeDayVC(goal: Goal)
}

final class NewGoalViewController: UIViewController {

//MARK: - Views
Expand All @@ -19,6 +23,7 @@ final class NewGoalViewController: UIViewController {
//MARK: - Properties
private let viewModel: NewGoalViewModel = NewGoalViewModel(saveUseCase: .init())
private let maxGoalLength = 15
weak var newGoalViewControllerDelegate: NewGoalViewControllerDelegate?

//MARK: - Life Cycle
override func viewDidLoad() {
Expand All @@ -35,7 +40,16 @@ final class NewGoalViewController: UIViewController {

//MARK: - IBActions
@IBAction func clickedStartButton(_ sender: UIButton) {
goThreeDayVC()
guard let goalText = goalTextField.text else {
return
}

let goal = Goal(goal: goalText, createdAt: Date())
saveGoal(with: goal)

dismiss(animated: true) { [weak self] in
self?.newGoalViewControllerDelegate?.goThreeDayVC(goal: goal)
}
}

//MARK: - Setup
Expand Down Expand Up @@ -107,20 +121,6 @@ final class NewGoalViewController: UIViewController {
}

//MARK: - Methods
private func goThreeDayVC() {
guard let goalText = goalTextField.text,
let threeDayVC = ThreeDayViewController.instantiate as? ThreeDayViewController else {
return
}

let goal = Goal(goal: goalText, createdAt: .init())

saveGoal(with: goal)

threeDayVC.goal = goal
navigationController?.pushViewController(threeDayVC, animated: true)
}

private func saveGoal(with goal: Goal) {
viewModel.action(.save(goal))
}
Expand Down

0 comments on commit 87cbe48

Please # to comment.