Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,35 @@ enum BookRegistrationStatus: String {
return .after
}
}

func getSubTitle() -> String {
switch self {
case .before:
return "책을 읽으면서 독서 기록을 남길 수 있어요"
case .inProgress:
return "독서 기록을 바로 시작할까요?"
case .after:
return "기억에 남은 문장이나 감상을 기록해보세요"
}
}

func getCancelButtonTitle() -> String {
switch self {
case .before:
return "확인"
case .inProgress, .after:
return "나중에 하기"
}
}

func getNextButtonTitle() -> String {
switch self {
case .inProgress:
return "기록 시작하기"
case .after:
return "기록 남기기"
default:
return ""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,19 @@ final class SearchViewController: BaseViewController<SearchView>, ScreenLoggable
.store(in: &cancellable)

viewModel.statePublisher
.compactMap { $0.isUpserted }
.removeDuplicates()
.compactMap { state -> (isbn: String, status: BookRegistrationStatus)? in
guard let isbn = state.isUpserted,
let status = state.selectedStatus else {
return nil
}
return (isbn, status)
}
.removeDuplicates { previous, current in
return previous.isbn == current.isbn && previous.status == current.status
}
.receive(on: DispatchQueue.main)
.sink { [weak self] isbn in
self?.presentNoteSuggestion(with: isbn)
.sink { [weak self] (isbn, status) in
self?.presentNoteSuggestion(with: isbn, status: status)
self?.viewModel.send(.noteSuggestionShown)
}
.store(in: &cancellable)
Expand Down Expand Up @@ -273,32 +281,49 @@ private extension SearchViewController {
viewModel.send(.upsertBook(isbn: isbn, status: status))
}

func presentNoteSuggestion(with isbn: String) {
func presentNoteSuggestion(with isbn: String, status: BookRegistrationStatus) {
let graphic = BKImage.Graphics.coinCheck
let graphicView = UIImageView(image: graphic)
graphicView.snp.makeConstraints {
$0.size.equalTo(CGSize(width: 120, height: 120))
}

let sheetTitle = "도서가 등록되었어요!"
let cancelAction : (() -> Void)? = { [weak self] in
self?.dismiss(animated: true)
self?.hideLoading()
}

let nextAction : (() -> Void)? = { [weak self] in
self?.dismiss(animated: true)
self?.viewModel.send(.loadNoteFlow)
self?.hideLoading()

}
logScreenView(name: GATracking.SearchAndRegister.complete)

var buttonGroup: BKButtonGroup?

if status == .before {
buttonGroup = .singleFullButton(
title: status.getCancelButtonTitle(),
action: cancelAction
)
} else {
buttonGroup = .twoButtonGroup(
leftTitle: status.getCancelButtonTitle(),
rightTitle: status.getNextButtonTitle(),
leftAction: cancelAction,
rightAction: nextAction
)
}

let sheet = BKBottomSheetViewController(
title: "도서가 등록되었어요!",
subtitle: "독서 기록을 바로 시작할까요?",
title: sheetTitle,
subtitle: status.getSubTitle(),
style: .centered,
suppliedContentStyle: .upper(graphicView),
buttonConfiguration: .twoButtonGroup(
leftTitle: "나중에 하기",
rightTitle: "기록 시작하기",
leftAction: { [weak self] in
self?.dismiss(animated: true)
self?.hideLoading()
},
rightAction: { [weak self] in
self?.dismiss(animated: true)
self?.viewModel.send(.loadNoteFlow)
self?.hideLoading()
}
)
buttonConfiguration: buttonGroup
)

sheet.show(from: self, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ final class SearchViewModel: BaseViewModel {
var searchBarPlaceholder: String
var searchViewTitle: String
var isUpserted: String? = nil
var selectedStatus: BookRegistrationStatus? = nil
var viewType: SearchViewType? = nil
}

Expand Down Expand Up @@ -274,6 +275,7 @@ final class SearchViewModel: BaseViewModel {
newState.error = .unauthorized
} else {
newState.isLoading = true
newState.selectedStatus = status
effects.append(.upsert(isbn: isbn, status: status))
}

Expand All @@ -284,6 +286,7 @@ final class SearchViewModel: BaseViewModel {

case .noteSuggestionShown:
newState.isUpserted = nil
newState.selectedStatus = nil

case .errorOccured(let error):
newState.isLoading = false
Expand Down
Loading