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

[DA] 마감임박 타이머 만료시 이슈 대응 #191

Merged
merged 3 commits into from
Aug 26, 2022
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
10 changes: 1 addition & 9 deletions Projects/App/Sources/Common/SplashViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,11 @@ final class SplashViewModel: SplashViewModelProtocol {
}

private func changeRootViewController(deadlineData: Int) {

var isDeadlineDataExist = true

if deadlineData == 0 {
isDeadlineDataExist = false
}

let rootViewController = MainViewController(
MainViewModel(
network: Network(),
repository: CategoryRepository(CategoryService(network: Network())),
OCRRepository: OCRRepository(OCRService(network: Network())),
deadlineDataExist: isDeadlineDataExist
OCRRepository: OCRRepository(OCRService(network: Network()))
))

let navigationController = UINavigationController(rootViewController: rootViewController)
Expand Down
5 changes: 3 additions & 2 deletions Projects/App/Sources/Main/MainCollectionViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class MainCollectionViewDataSource: NSObject, UICollectionViewDataSource {
var didDeadLineCountdownTimeOver = PublishRelay<Void>()
var selectedCategoryIndexPath: IndexPath? = nil

private let disposeBag = DisposeBag()
private var deadLineDisposeBag = DisposeBag()

func numberOfSections(in collectionView: UICollectionView) -> Int {
// TODO: 마감임박 데이터 없을 때의 경우 처리 필요
Expand Down Expand Up @@ -67,7 +67,7 @@ final class MainCollectionViewDataSource: NSObject, UICollectionViewDataSource {
cell.gifticonApplyButtonDelegate = self
cell.countdownTimeOver
.bind(to: didDeadLineCountdownTimeOver)
.disposed(by: disposeBag)
.disposed(by: deadLineDisposeBag)
return cell
case .category:
guard let cell = collectionView.dequeReusableCell(CategoryCollectionViewCell.self,
Expand Down Expand Up @@ -112,6 +112,7 @@ final class MainCollectionViewDataSource: NSObject, UICollectionViewDataSource {
extension MainCollectionViewDataSource {
func updateDeadLineData(_ list: [GifticonCard]) {
deadLineData = list
deadLineDisposeBag = DisposeBag()
}

func updateCategoryData(_ list: [Category]) {
Expand Down
2 changes: 0 additions & 2 deletions Projects/App/Sources/Main/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ final class MainViewController: BaseViewController<MainViewModelProtocol> {
mainView.configureDataSource(viewModel.mainDataSource)
mainView.configureDelegate(viewModel.mainDelegate)

mainView.isDeadlineDataExist.accept(viewModel.isDeadlineDataExist.value)

view.addSubview(mainView)
mainView.snp.makeConstraints {
$0.top.equalTo(navigationBar.snp.bottom)
Expand Down
11 changes: 5 additions & 6 deletions Projects/App/Sources/Main/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,13 @@ final class MainViewModel: MainViewModelProtocol {
init(
network: Networking,
repository: CategoryRepositoryLogic,
OCRRepository: OCRRepositoryLogic,
deadlineDataExist: Bool
OCRRepository: OCRRepositoryLogic
) {
self.gifticonService = GifticonService(network: network)
self.categoryRepository = repository
self.OCRRepository = OCRRepository
self.isDeadlineDataExist.accept(deadlineDataExist)

deadlineInfo()
category()
gifticonList()
bind()
}

Expand Down Expand Up @@ -195,9 +191,12 @@ extension MainViewModel {
})
.disposed(by: disposeBag)

// 마감 시간이 지나고 바로 리스트 재요청 시 그대로 남아있는 이슈가 있음
// 따라서 delay 500ms를 추가함
mainDataSource.didDeadLineCountdownTimeOver
.delay(.milliseconds(500), scheduler: MainScheduler.instance)
.subscribe(onNext: { [weak self] in
self?.deadlineInfo()
self?.reload()
})
.disposed(by: disposeBag)
}
Expand Down
2 changes: 2 additions & 0 deletions Projects/App/Sources/Main/View/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ final class MainView: BaseView {
backgroundColor = .clear

isDeadlineDataExist
.skip(1)
.throttle(.milliseconds(500), scheduler: MainScheduler.instance)
Comment on lines +37 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 궁금한건데 skip이 지정한 횟수만큼 skip를 하는거라고 본거같은데 이게 왜 필요할까요?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BehaviorRelay는 subscribe시 가지고 있는 값을 방출하는 Hot Observable입니다.

따라서 해당 이벤트를 무시하기 위해 .skip(1)을 추가하였습니다.

자세한 내용은 아래 자료를 참고하시면 좋습니다. :)
https://okanghoon.medium.com/rxswift-2-observable-subject-relay-8fcd9b01913d

.subscribe(onNext: { [weak self] _ in
self?.reloadCollectionViewSection(.deadLine)
})
Expand Down
7 changes: 5 additions & 2 deletions Projects/App/Sources/Usecase/GifticonEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ struct GifticonEntity {

init(_ responseModel: [GifticonResponseModel] = []) {
gifticonList = responseModel.compactMap({ model in
GifticonCard(
// 마감 시간이 지난 경우 리스트에 노출되지 않도록 방어
guard model.sprinkleAt.fullStringDate().compare(Date()) != .orderedAscending else { return nil }
return GifticonCard(
sprinkleTime: model.sprinkleAt,
gifticonInfo: Gifticon(
id: model.sprinkleID,
Expand All @@ -22,7 +24,8 @@ struct GifticonEntity {
expirationDate: model.expiredAt,
category: Category(rawValue: model.category) ?? .all),
numberOfParticipants: model.participants,
isParticipating: model.participateIn)
isParticipating: model.participateIn
)
})
}
}