Skip to content

Commit 8fa0937

Browse files
committed
[BOOK-357] feat: VM에 변수 추가 및 VC에 적용
1 parent 9e55bf5 commit 8fa0937

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

src/Projects/BKPresentation/Sources/MainFlow/Search/View/SearchViewController.swift

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,19 @@ final class SearchViewController: BaseViewController<SearchView>, ScreenLoggable
168168
.store(in: &cancellable)
169169

170170
viewModel.statePublisher
171-
.compactMap { $0.isUpserted }
172-
.removeDuplicates()
171+
.compactMap { state -> (isbn: String, status: BookRegistrationStatus)? in
172+
guard let isbn = state.isUpserted,
173+
let status = state.selectedStatus else {
174+
return nil
175+
}
176+
return (isbn, status)
177+
}
178+
.removeDuplicates { previous, current in
179+
return previous.isbn == current.isbn && previous.status == current.status
180+
}
173181
.receive(on: DispatchQueue.main)
174-
.sink { [weak self] isbn in
175-
self?.presentNoteSuggestion(with: isbn)
182+
.sink { [weak self] (isbn, status) in
183+
self?.presentNoteSuggestion(with: isbn, status: status)
176184
self?.viewModel.send(.noteSuggestionShown)
177185
}
178186
.store(in: &cancellable)
@@ -273,32 +281,49 @@ private extension SearchViewController {
273281
viewModel.send(.upsertBook(isbn: isbn, status: status))
274282
}
275283

276-
func presentNoteSuggestion(with isbn: String) {
284+
func presentNoteSuggestion(with isbn: String, status: BookRegistrationStatus) {
277285
let graphic = BKImage.Graphics.coinCheck
278286
let graphicView = UIImageView(image: graphic)
279287
graphicView.snp.makeConstraints {
280288
$0.size.equalTo(CGSize(width: 120, height: 120))
281289
}
290+
291+
let sheetTitle = "도서가 등록되었어요!"
292+
let cancelAction : (() -> Void)? = { [weak self] in
293+
self?.dismiss(animated: true)
294+
self?.hideLoading()
295+
}
296+
297+
let nextAction : (() -> Void)? = { [weak self] in
298+
self?.dismiss(animated: true)
299+
self?.viewModel.send(.loadNoteFlow)
300+
self?.hideLoading()
301+
302+
}
282303
logScreenView(name: GATracking.SearchAndRegister.complete)
283304

305+
var buttonGroup: BKButtonGroup?
306+
307+
if status == .before {
308+
buttonGroup = .singleFullButton(
309+
title: status.getCancelButtonTitle(),
310+
action: cancelAction
311+
)
312+
} else {
313+
buttonGroup = .twoButtonGroup(
314+
leftTitle: status.getCancelButtonTitle(),
315+
rightTitle: status.getNextButtonTitle(),
316+
leftAction: cancelAction,
317+
rightAction: nextAction
318+
)
319+
}
320+
284321
let sheet = BKBottomSheetViewController(
285-
title: "도서가 등록되었어요!",
286-
subtitle: "독서 기록을 바로 시작할까요?",
322+
title: sheetTitle,
323+
subtitle: status.getSubTitle(),
287324
style: .centered,
288325
suppliedContentStyle: .upper(graphicView),
289-
buttonConfiguration: .twoButtonGroup(
290-
leftTitle: "나중에 하기",
291-
rightTitle: "기록 시작하기",
292-
leftAction: { [weak self] in
293-
self?.dismiss(animated: true)
294-
self?.hideLoading()
295-
},
296-
rightAction: { [weak self] in
297-
self?.dismiss(animated: true)
298-
self?.viewModel.send(.loadNoteFlow)
299-
self?.hideLoading()
300-
}
301-
)
326+
buttonConfiguration: buttonGroup
302327
)
303328

304329
sheet.show(from: self, animated: true)

src/Projects/BKPresentation/Sources/MainFlow/Search/ViewModel/SearchViewModel.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ final class SearchViewModel: BaseViewModel {
9292
var searchBarPlaceholder: String
9393
var searchViewTitle: String
9494
var isUpserted: String? = nil
95+
var selectedStatus: BookRegistrationStatus? = nil
9596
var viewType: SearchViewType? = nil
9697
}
9798

@@ -274,6 +275,7 @@ final class SearchViewModel: BaseViewModel {
274275
newState.error = .unauthorized
275276
} else {
276277
newState.isLoading = true
278+
newState.selectedStatus = status
277279
effects.append(.upsert(isbn: isbn, status: status))
278280
}
279281

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

285287
case .noteSuggestionShown:
286288
newState.isUpserted = nil
289+
newState.selectedStatus = nil
287290

288291
case .errorOccured(let error):
289292
newState.isLoading = false

0 commit comments

Comments
 (0)