Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chane home emptyview title (#186) #187

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Projects/App/Sources/Screens/Home/HomeReactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ final class HomeReactor: Reactor {
initialState = .init(
works: [],
dates: (startDate: Date(), endDate: Date()),
username: "")
username: "",
emptyViewState: .today)
}

enum Action {
Expand All @@ -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<Mutation> {
Expand All @@ -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)
}
}

Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Projects/App/Sources/Screens/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion Projects/App/Sources/Screens/Home/Views/HomeEmptyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down