Skip to content

Commit

Permalink
Merge pull request #122 from boostcampwm-2022/refactor/QuestViewHeade…
Browse files Browse the repository at this point in the history
…rLabel

Refactor/quest view header label
  • Loading branch information
jinwoong16 committed Dec 9, 2022
2 parents 3efe71f + 1f3d95d commit b720787
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ final class QuestViewHeader: UIStackView {
var buttonDidClick = PublishSubject<Void>()

// MARK: - Components
private lazy var titleLabel: UILabel = {
private(set) lazy var titleLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.text = "Today Quest"
titleLabel.text = "Today Quests"
titleLabel.textColor = .maxViolet
titleLabel.font = UIFont.boldSystemFont(ofSize: 32)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,21 @@ final class HomeViewController: UIViewController {
disposeBag: disposableBag
)

bindToQuestViewHeader(with: output)
bindToCalendarView(with: output)
bindToQuestHeaderButton()
bindToQuestView(with: output)
bindToStatusView(with: output)

}

private func bindToQuestViewHeader(with output: HomeViewModel.Output) {
output
.questHeaderLabel
.bind(to: questViewHeader.titleLabel.rx.text)
.disposed(by: disposableBag)
}

private func bindToCalendarView(with output: HomeViewModel.Output) {
output
.displayDays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class HomeViewModel {
}

struct Output {
let questHeaderLabel: Observable<String>
let data: Driver<[Quest]>
let userData: Observable<User>
let questStatus: Driver<(Int, Int)>
Expand Down Expand Up @@ -78,6 +79,11 @@ final class HomeViewModel {
return !result.isEmpty ? owner.currentDate : nil
}

let questHeaderLabel = input
.daySelected
.map(calculateRelative(_:))
.asObservable()

let data = Observable
.merge(
updated,
Expand Down Expand Up @@ -175,11 +181,26 @@ final class HomeViewModel {
})
.disposed(by: disposeBag)

return Output(data: data,
return Output(questHeaderLabel: questHeaderLabel,
data: data,
userData: userData,
questStatus: questStatus,
profileTapResult: profileTapResult,
currentMonth: currentMonth,
displayDays: displayDays)
}
}

private extension HomeViewModel {
func calculateRelative(_ date: Date) -> String {
let today = Date()

if today.startOfDay > date.startOfDay {
return "Previous Quests"
} else if today.startOfDay < date.startOfDay {
return "Upcomming Quests"
} else {
return "Today Quests"
}
}
}

0 comments on commit b720787

Please sign in to comment.