diff --git a/src/Projects/BKPresentation/Sources/MainFlow/Search/VO/BookRegistrationStatus.swift b/src/Projects/BKPresentation/Sources/MainFlow/Search/VO/BookRegistrationStatus.swift index 99afff7c..d3f858a3 100644 --- a/src/Projects/BKPresentation/Sources/MainFlow/Search/VO/BookRegistrationStatus.swift +++ b/src/Projects/BKPresentation/Sources/MainFlow/Search/VO/BookRegistrationStatus.swift @@ -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 "" + } + } } diff --git a/src/Projects/BKPresentation/Sources/MainFlow/Search/View/SearchViewController.swift b/src/Projects/BKPresentation/Sources/MainFlow/Search/View/SearchViewController.swift index 8f5648de..5dfe24c4 100644 --- a/src/Projects/BKPresentation/Sources/MainFlow/Search/View/SearchViewController.swift +++ b/src/Projects/BKPresentation/Sources/MainFlow/Search/View/SearchViewController.swift @@ -168,11 +168,19 @@ final class SearchViewController: BaseViewController, 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) @@ -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) diff --git a/src/Projects/BKPresentation/Sources/MainFlow/Search/ViewModel/SearchViewModel.swift b/src/Projects/BKPresentation/Sources/MainFlow/Search/ViewModel/SearchViewModel.swift index 6b94ea2c..7a06c0f3 100644 --- a/src/Projects/BKPresentation/Sources/MainFlow/Search/ViewModel/SearchViewModel.swift +++ b/src/Projects/BKPresentation/Sources/MainFlow/Search/ViewModel/SearchViewModel.swift @@ -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 } @@ -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)) } @@ -284,6 +286,7 @@ final class SearchViewModel: BaseViewModel { case .noteSuggestionShown: newState.isUpserted = nil + newState.selectedStatus = nil case .errorOccured(let error): newState.isLoading = false