From 78757049908af6c33f8c0be6a7ca55b7c216343b Mon Sep 17 00:00:00 2001 From: Zoe Date: Mon, 23 Sep 2024 03:31:33 +0900 Subject: [PATCH] =?UTF-8?q?[Feat/#42]=20=EC=98=B5=EC=85=98=20=EC=84=A0?= =?UTF-8?q?=ED=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OptionSelectViewController.swift | 31 +++++++++++-------- .../ProductDetailViewController.swift | 6 ++-- .../TableViewCell/TermsTableViewCell.swift | 2 +- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/DDANZI_iOS/DDANZI_iOS/Presentation/ProductDetail/ViewControllers/OptionSelect/OptionSelectViewController.swift b/DDANZI_iOS/DDANZI_iOS/Presentation/ProductDetail/ViewControllers/OptionSelect/OptionSelectViewController.swift index fcc1137..f130962 100644 --- a/DDANZI_iOS/DDANZI_iOS/Presentation/ProductDetail/ViewControllers/OptionSelect/OptionSelectViewController.swift +++ b/DDANZI_iOS/DDANZI_iOS/Presentation/ProductDetail/ViewControllers/OptionSelect/OptionSelectViewController.swift @@ -115,7 +115,8 @@ final class OptionSelectViewController: UIViewController { bottomButton.button.rx.tap .bind { self.dismiss(animated: true) { - self.delegate?.optionViewControllerDidFinish(self) + let unwrappedOptions = self.selectedOptions.compactMap { $0 } + self.delegate?.optionViewControllerDidFinish(self, optionList: unwrappedOptions) Amplitude.instance().logEvent("click_option_next") } } @@ -154,26 +155,30 @@ final class OptionSelectViewController: UIViewController { optionCollectionView.rx.itemSelected .bind(with: self) { owner, indexPath in - if let cell = owner.optionCollectionView.cellForItem(at: indexPath) as? OptionCollectionViewCell { - cell.isSelectedRelay.accept(true) - owner.selectedOptions[indexPath.section] = self.option[indexPath.section].optionDetailList[indexPath.row].optionDetailID - owner.updateButtonState() + // 섹션 내 이전 선택 해제 + if let selectedIndex = owner.selectedOptions[indexPath.section] { + let deselectedIndexPath = IndexPath(row: selectedIndex, section: indexPath.section) + if let cell = owner.optionCollectionView.cellForItem(at: deselectedIndexPath) as? OptionCollectionViewCell { + cell.isSelectedRelay.accept(false) // 이전 선택 해제 + } } - } - .disposed(by: disposeBag) - - optionCollectionView.rx.itemDeselected - .bind(with: self) { owner, indexPath in + + // 선택한 옵션을 섹션별로 저장 + let selectedOptionId = owner.option[indexPath.section].optionDetailList[indexPath.row].optionDetailID + owner.selectedOptions[indexPath.section] = selectedOptionId // optionDetailId 저장 + if let cell = owner.optionCollectionView.cellForItem(at: indexPath) as? OptionCollectionViewCell { - cell.isSelectedRelay.accept(false) - owner.selectedOptions[indexPath.section] = nil - owner.updateButtonState() + cell.isSelectedRelay.accept(true) // 새로운 선택 적용 } + + owner.updateButtonState() // 버튼 상태 업데이트 } .disposed(by: disposeBag) + } private func updateButtonState() { + print(selectedOptions) let allSectionsSelected = selectedOptions.allSatisfy { $0 != nil } bottomButton.button.isEnabled = allSectionsSelected bottomButton.button.backgroundColor = allSectionsSelected ? .black : .gray2 diff --git a/DDANZI_iOS/DDANZI_iOS/Presentation/ProductDetail/ViewControllers/ProductDetailViewController.swift b/DDANZI_iOS/DDANZI_iOS/Presentation/ProductDetail/ViewControllers/ProductDetailViewController.swift index 9920a0c..4fbbb0b 100644 --- a/DDANZI_iOS/DDANZI_iOS/Presentation/ProductDetail/ViewControllers/ProductDetailViewController.swift +++ b/DDANZI_iOS/DDANZI_iOS/Presentation/ProductDetail/ViewControllers/ProductDetailViewController.swift @@ -16,7 +16,7 @@ import Amplitude // MARK: - OptionDelegate protocol OptionViewControllerDelegate: AnyObject { - func optionViewControllerDidFinish(_ viewController: OptionSelectViewController) + func optionViewControllerDidFinish(_ viewController: OptionSelectViewController, optionList: [Int]) } final class ProductDetailViewController: UIViewController { @@ -324,9 +324,9 @@ final class ProductDetailViewController: UIViewController { } extension ProductDetailViewController: OptionViewControllerDelegate { - func optionViewControllerDidFinish(_ viewController: OptionSelectViewController) { + func optionViewControllerDidFinish(_ viewController: OptionSelectViewController, optionList: [Int]) { let purchaseVC = PurchaseViewController() - purchaseVC.orderModel = .init(productId: productId, optionList: optionList.map({ $0.optionID })) + purchaseVC.orderModel = .init(productId: productId, optionList: optionList) self.navigationController?.pushViewController(purchaseVC, animated: true) } } diff --git a/DDANZI_iOS/DDANZI_iOS/Presentation/Purchase/TableViewCell/TermsTableViewCell.swift b/DDANZI_iOS/DDANZI_iOS/Presentation/Purchase/TableViewCell/TermsTableViewCell.swift index ba50c18..2d7838e 100644 --- a/DDANZI_iOS/DDANZI_iOS/Presentation/Purchase/TableViewCell/TermsTableViewCell.swift +++ b/DDANZI_iOS/DDANZI_iOS/Presentation/Purchase/TableViewCell/TermsTableViewCell.swift @@ -51,7 +51,7 @@ final class TermsTableViewCell: UITableViewCell { private func setConstraints() { containerView.snp.makeConstraints { $0.height.equalTo(38) - $0.horizontalEdges.equalToSuperview().inset(20) + $0.horizontalEdges.equalToSuperview() $0.verticalEdges.equalToSuperview().inset(5) }