From bfb79e3b3955fb44223b27c039eb868a2f473562 Mon Sep 17 00:00:00 2001 From: hyesu kim <68391767+hyesuuou@users.noreply.github.com> Date: Mon, 19 Jun 2023 16:46:46 +0900 Subject: [PATCH] fix: chane home emptyview title (#186) --- .../Sources/Screens/Home/HomeReactor.swift | 11 ++++++++-- .../Screens/Home/HomeViewController.swift | 9 +++++++++ .../Screens/Home/Views/HomeEmptyView.swift | 20 ++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Projects/App/Sources/Screens/Home/HomeReactor.swift b/Projects/App/Sources/Screens/Home/HomeReactor.swift index 85063c6..8364195 100644 --- a/Projects/App/Sources/Screens/Home/HomeReactor.swift +++ b/Projects/App/Sources/Screens/Home/HomeReactor.swift @@ -27,7 +27,8 @@ final class HomeReactor: Reactor { initialState = .init( works: [], dates: (startDate: Date(), endDate: Date()), - username: "") + username: "", + emptyViewState: .today) } enum Action { @@ -39,12 +40,14 @@ final class HomeReactor: Reactor { var works: [Work] var dates: (startDate: Date, endDate: Date) var username: String + var emptyViewState: HomeEmptyView.EmptyViewType } enum Mutation { case setProjects([Work]) case setName(String) case setDate(Date, Date) + case setEmptyViewState(HomeEmptyView.EmptyViewType) } func mutate(action: Action) -> Observable { @@ -64,7 +67,9 @@ final class HomeReactor: Reactor { start: startDate, end: endDate) .map { Mutation.setProjects($0) } - return Observable.concat(date, works) + let sameDate = startDate == endDate + let emptyState = Observable.just(Mutation.setEmptyViewState(sameDate ? .today : .range)) + return Observable.concat(emptyState, date, works) } } @@ -78,6 +83,8 @@ final class HomeReactor: Reactor { newState.username = name case .setDate(let startDate, let endDate): newState.dates = (startDate, endDate) + case .setEmptyViewState(let emptyViewState): + newState.emptyViewState = emptyViewState } return newState diff --git a/Projects/App/Sources/Screens/Home/HomeViewController.swift b/Projects/App/Sources/Screens/Home/HomeViewController.swift index 14e2300..1dafb31 100644 --- a/Projects/App/Sources/Screens/Home/HomeViewController.swift +++ b/Projects/App/Sources/Screens/Home/HomeViewController.swift @@ -153,6 +153,15 @@ final class HomeViewController: BaseViewController, View { owner.applySnapshot(works: owner.reactor?.currentState.works ?? []) } .disposed(by: disposeBag) + + reactor.state + .map { $0.emptyViewState } + .withUnretained(self) + .bind { owner, emptyState in + print(emptyState) + owner.homeEmptyView.setEmptyViewType(type: emptyState) + } + .disposed(by: disposeBag) } // MARK: - Methods diff --git a/Projects/App/Sources/Screens/Home/Views/HomeEmptyView.swift b/Projects/App/Sources/Screens/Home/Views/HomeEmptyView.swift index 5e2a017..c6e115d 100644 --- a/Projects/App/Sources/Screens/Home/Views/HomeEmptyView.swift +++ b/Projects/App/Sources/Screens/Home/Views/HomeEmptyView.swift @@ -12,6 +12,20 @@ import UIKit import SnapKit final class HomeEmptyView: UIView { + + enum EmptyViewType { + case today + case range + + var title: String { + switch self { + case .today: + return "오늘의 기록이 없어요" + case .range: + return "작성된 기록이 없어요" + } + } + } private let emptyImageView: UIImageView = { let imageView = UIImageView() @@ -22,7 +36,7 @@ final class HomeEmptyView: UIView { private let titleLabel: UILabel = { let label = UILabel() - label.text = "아직 작성된 기록이 없어요" + label.text = EmptyViewType.today.title label.font = .h4M label.textColor = .wkBlack45 label.textAlignment = .center @@ -52,6 +66,10 @@ final class HomeEmptyView: UIView { fatalError("init(coder:) has not been implemented") } + internal func setEmptyViewType(type: EmptyViewType) { + self.titleLabel.text = type.title + } + private func setLayout() { self.stackView.axis = .vertical