From 823b633c2a0c2cc26a861c7d695715f403d263f1 Mon Sep 17 00:00:00 2001 From: L-j-h-c Date: Thu, 22 Dec 2022 20:17:51 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[Feat]=20#54=20-=20Entity=20=EB=B0=8F=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B0=94=EC=9D=B8=EB=94=A9=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/Sources/Model/RankingModel.swift | 21 +++++++++++++--- .../RankingScene/Cells/RankingChartCVC.swift | 6 +++-- .../RankingScene/Cells/RankingListCVC.swift | 9 +++++-- .../Sources/RankingScene/VC/RankingVC.swift | 25 ++++++++++--------- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/SOPT-Stamp-iOS/Projects/Domain/Sources/Model/RankingModel.swift b/SOPT-Stamp-iOS/Projects/Domain/Sources/Model/RankingModel.swift index 6c679457..38335cee 100644 --- a/SOPT-Stamp-iOS/Projects/Domain/Sources/Model/RankingModel.swift +++ b/SOPT-Stamp-iOS/Projects/Domain/Sources/Model/RankingModel.swift @@ -8,9 +8,24 @@ import Foundation -public struct RankingModel { +public struct RankingModel: Hashable { + public let username: String + public let usreId: Int + public let score: Int + public let sentence: String + + public init(username: String, usreId: Int, score: Int, sentence: String) { + self.username = username + self.usreId = usreId + self.score = score + self.sentence = sentence + } +} - public init() { - +public struct RankingChartModel: Hashable { + public let ranking: [RankingModel] + + public init(ranking: [RankingModel]) { + self.ranking = ranking } } diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift index a2b1db43..a7728101 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift @@ -100,9 +100,11 @@ extension RankingChartCVC { baloonViews.removeAll() } - public func setData(model: String) { + public func setData(model: RankingChartModel) { - for (index, sentence) in ["안녕하세요", "제가 일등일 수도 있습니다 하하", "그래"].enumerated() { + let sentences = model.ranking.map { $0.sentence } + + for (index, sentence) in sentences.enumerated() { var baloonView: SpeechBalloonView if index == 0 { baloonView = SpeechBalloonView.init(level: .rankTwo, sentence: sentence) diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListCVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListCVC.swift index 673fc557..a3fc2f12 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListCVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListCVC.swift @@ -116,7 +116,12 @@ extension RankingListCVC { extension RankingListCVC { - public func setData(model: String) { - + public func setData(model: RankingModel, rank: Int) { + rankLabel.text = String(rank) + usernameLabel.text = model.username + sentenceLabel.text = model.sentence + scoreLabel.text = "\(model.score)점" + scoreLabel.partFontChange(targetString: "점", + font: DSKitFontFamily.Pretendard.medium.font(size: 12)) } } diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift index 2790f4f7..77e0feca 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift @@ -9,6 +9,7 @@ import UIKit import Core +import Domain import DSKit import Combine @@ -56,7 +57,6 @@ public class RankingVC: UIViewController { self.registerCells() self.bindViewModels() self.setDataSource() - self.applySnapshot() } } @@ -106,29 +106,30 @@ extension RankingVC { dataSource = UICollectionViewDiffableDataSource(collectionView: rankingCollectionView, cellProvider: { collectionView, indexPath, itemIdentifier in switch RankingSection.type(indexPath.section) { case .chart: - guard let chartCell = collectionView.dequeueReusableCell(withReuseIdentifier: RankingChartCVC.className, for: indexPath) as? RankingChartCVC else { return UICollectionViewCell() } - chartCell.setData(model: "") + guard let chartCell = collectionView.dequeueReusableCell(withReuseIdentifier: RankingChartCVC.className, for: indexPath) as? RankingChartCVC, + let chartCellModel = itemIdentifier as? RankingChartModel else { return UICollectionViewCell() } + chartCell.setData(model: chartCellModel) return chartCell case .list: - guard let rankingListCell = collectionView.dequeueReusableCell(withReuseIdentifier: RankingListCVC.className, for: indexPath) as? RankingListCVC else { return UICollectionViewCell() } - guard let index = itemIdentifier as? Int else { return UICollectionViewCell() } + guard let rankingListCell = collectionView.dequeueReusableCell(withReuseIdentifier: RankingListCVC.className, for: indexPath) as? RankingListCVC, + let rankingListCellModel = itemIdentifier as? RankingModel else { return UICollectionViewCell() } + rankingListCell.setData(model: rankingListCellModel, rank: indexPath.row + 1) return rankingListCell } }) } - func applySnapshot() { + func applySnapshot(model: [RankingModel]) { var snapshot = NSDiffableDataSourceSnapshot() snapshot.appendSections([.chart, .list]) - snapshot.appendItems([-1], toSection: .chart) - var tempItems: [Int] = [] - for i in 0..<50 { - tempItems.append(i) - } - snapshot.appendItems(tempItems, toSection: .list) + guard let chartCellModels = Array(model[0...2]) as? [RankingModel], + let rankingListModel = Array(model[3...model.count-1]) as? [RankingModel] else { return } + let chartCellModel = RankingChartModel.init(ranking: chartCellModels) + snapshot.appendItems([chartCellModel], toSection: .chart) + snapshot.appendItems(rankingListModel, toSection: .list) dataSource.apply(snapshot, animatingDifferences: false) self.view.setNeedsLayout() } From 091364ff49213fc41e4a8c48732f18f9e4100b8d Mon Sep 17 00:00:00 2001 From: L-j-h-c Date: Thu, 22 Dec 2022 21:24:18 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[Feat]=20#54=20-=20=EC=B0=A8=ED=8A=B8=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B0=94=EC=9D=B8=EB=94=A9=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=B0=8F=20=EB=8D=94=EB=AF=B8=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/RankingRepository.swift | 6 +++- .../Sources/Transform/Rankingtransform.swift | 6 ++-- .../RankingRepositoryInterface.swift | 2 +- .../Sources/UseCase/RankingUseCase.swift | 22 ++++++++++--- .../Components/ChartRectangleView.swift | 11 ++++++- .../Components/SpeechBalloonView.swift | 15 ++++++--- .../RankingScene/Cells/RankingChartCVC.swift | 19 +++++++++++- .../Sources/RankingScene/VC/RankingVC.swift | 12 +++++-- .../ViewModel/RankingViewModel.swift | 31 +++++++++++++------ 9 files changed, 95 insertions(+), 29 deletions(-) diff --git a/SOPT-Stamp-iOS/Projects/Data/Sources/Repository/RankingRepository.swift b/SOPT-Stamp-iOS/Projects/Data/Sources/Repository/RankingRepository.swift index 0966314e..8fed7014 100644 --- a/SOPT-Stamp-iOS/Projects/Data/Sources/Repository/RankingRepository.swift +++ b/SOPT-Stamp-iOS/Projects/Data/Sources/Repository/RankingRepository.swift @@ -23,5 +23,9 @@ public class RankingRepository { } extension RankingRepository: RankingRepositoryInterface { - + public func fetchRankingListModel() -> AnyPublisher<[Domain.RankingModel], Error> { + return Future<[RankingModel], Error> { promise in + promise(.success([RankingModel.init(username: "1등이다", usreId: 1, score: 94, sentence: "제가 1등입니다"), RankingModel.init(username: "헬로", usreId: 2, score: 92, sentence: "2등"), RankingModel.init(username: "이름이 긴 사람", usreId: 3, score: 91, sentence: "제가 3등입니다 말이 길어지면 어케"), RankingModel.init(username: "더미데이름", usreId: 4, score: 86, sentence: "4444"), RankingModel.init(username: "레포지토리", usreId: 5, score: 65, sentence: "5"), RankingModel.init(username: "인터페이스", usreId: 6, score: 53, sentence: "ㅎㄴ마ㄷ한마디"), RankingModel.init(username: "솝트", usreId: 7, score: 53, sentence: "하남ㄴㅁㅇㄹㅁㅋㅌㅊㅍ"), RankingModel.init(username: "노가다", usreId: 8, score: 52, sentence: "한마디 띄우기"), RankingModel.init(username: "9등이다", usreId: 9, score: 40, sentence: "한마디 최고글자길이는몇일까여?"), RankingModel.init(username: "10등이다", usreId: 10, score: 35, sentence: "5166"), RankingModel.init(username: "11등이다", usreId: 11, score: 32, sentence: "더메대충이데머"), RankingModel.init(username: "12등이다", usreId: 12, score: 12, sentence: "대충 더미데잍"), RankingModel.init(username: "안녕하세요", usreId: 13, score: 7, sentence: "531542642"), RankingModel.init(username: "14등이다", usreId: 14, score: 5, sentence: "한마디 귀찮아"), RankingModel.init(username: "15등이다", usreId: 15, score: 3, sentence: "")])) + }.eraseToAnyPublisher() + } } diff --git a/SOPT-Stamp-iOS/Projects/Data/Sources/Transform/Rankingtransform.swift b/SOPT-Stamp-iOS/Projects/Data/Sources/Transform/Rankingtransform.swift index 47878ba2..efcdb33a 100644 --- a/SOPT-Stamp-iOS/Projects/Data/Sources/Transform/Rankingtransform.swift +++ b/SOPT-Stamp-iOS/Projects/Data/Sources/Transform/Rankingtransform.swift @@ -13,7 +13,7 @@ import Network extension RankingEntity { - public func toDomain() -> RankingModel { - return RankingModel.init() - } +// public func toDomain() -> RankingModel { +// return RankingModel.init() +// } } diff --git a/SOPT-Stamp-iOS/Projects/Domain/Sources/RepositoryInterface/RankingRepositoryInterface.swift b/SOPT-Stamp-iOS/Projects/Domain/Sources/RepositoryInterface/RankingRepositoryInterface.swift index 0c4d487a..96eeee1e 100644 --- a/SOPT-Stamp-iOS/Projects/Domain/Sources/RepositoryInterface/RankingRepositoryInterface.swift +++ b/SOPT-Stamp-iOS/Projects/Domain/Sources/RepositoryInterface/RankingRepositoryInterface.swift @@ -9,5 +9,5 @@ import Combine public protocol RankingRepositoryInterface { - + func fetchRankingListModel() -> AnyPublisher<[RankingModel], Error> } diff --git a/SOPT-Stamp-iOS/Projects/Domain/Sources/UseCase/RankingUseCase.swift b/SOPT-Stamp-iOS/Projects/Domain/Sources/UseCase/RankingUseCase.swift index 9574063f..ef23f487 100644 --- a/SOPT-Stamp-iOS/Projects/Domain/Sources/UseCase/RankingUseCase.swift +++ b/SOPT-Stamp-iOS/Projects/Domain/Sources/UseCase/RankingUseCase.swift @@ -8,20 +8,32 @@ import Combine -public protocol RankingUseCase { +import Core +public protocol RankingUseCase { + func fetchRankingList() + var rankingListModelFetched: PassthroughSubject<[RankingModel], Error> { get } } public class DefaultRankingUseCase { - + private let repository: RankingRepositoryInterface - private var cancelBag = Set() - + private var cancelBag = CancelBag() + public var rankingListModelFetched = PassthroughSubject<[RankingModel], Error>() + public init(repository: RankingRepositoryInterface) { self.repository = repository } } extension DefaultRankingUseCase: RankingUseCase { - + public func fetchRankingList() { + self.repository.fetchRankingListModel() + .withUnretained(self) + .sink { completion in + print(completion) + } receiveValue: { owner, model in + owner.rankingListModelFetched.send(model) + }.store(in: self.cancelBag) + } } diff --git a/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/ChartRectangleView.swift b/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/ChartRectangleView.swift index c6683d08..50bbc989 100644 --- a/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/ChartRectangleView.swift +++ b/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/ChartRectangleView.swift @@ -174,7 +174,16 @@ extension ChartRectangleView { } extension ChartRectangleView { - static func ==(left: ChartRectangleView, right: ChartRectangleView) -> Bool { + public func setData(score: Int, username: String) { + self.usernameLabel.text = username + self.scoreLabel.text = "\(score)점" + self.scoreLabel.partFontChange(targetString: "점", + font: DSKitFontFamily.Pretendard.medium.font(size: 12)) + } +} + +extension ChartRectangleView { + static func == (left: ChartRectangleView, right: ChartRectangleView) -> Bool { return left.viewLevel == right.viewLevel } } diff --git a/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/SpeechBalloonView.swift b/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/SpeechBalloonView.swift index be7a1c08..8555ba04 100644 --- a/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/SpeechBalloonView.swift +++ b/SOPT-Stamp-iOS/Projects/Modules/DSKit/Sources/Components/SpeechBalloonView.swift @@ -83,10 +83,15 @@ extension SpeechBalloonView { make.top.equalToSuperview() let standardSize = calculateLabelSize(sentence: sentence) - if standardSize < 108.adjusted { - make.width.equalTo(108.adjusted + 20) + let smallBalloonMinimumWidth: CGFloat = 108 + let smallBalloonCompensates: CGFloat = 10 + let smallBalloonWidth = smallBalloonMinimumWidth - smallBalloonCompensates + let largeBalloonCompensates: CGFloat = 30 * standardSize / 266.adjusted + + if standardSize < smallBalloonWidth.adjusted { + make.width.equalTo(smallBalloonWidth.adjusted + smallBalloonCompensates) } else if standardSize < 266.adjusted { - make.width.equalTo(standardSize + 40) + make.width.equalTo(standardSize + largeBalloonCompensates) } else { make.width.lessThanOrEqualToSuperview() sentenceLabel.lineBreakMode = .byTruncatingTail @@ -121,9 +126,9 @@ extension SpeechBalloonView { private func calculateLabelSize(sentence: String) -> CGFloat { let tempLabel = BalloonPaddingLabel() tempLabel.text = sentence - tempLabel.sizeToFit() tempLabel.setTypoStyle(.subtitle3) - return tempLabel.frame.width + tempLabel.sizeToFit() + return tempLabel.intrinsicContentSize.width } } diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift index a7728101..0486113e 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift @@ -102,8 +102,17 @@ extension RankingChartCVC { public func setData(model: RankingChartModel) { - let sentences = model.ranking.map { $0.sentence } + // 데이터 바인딩을 위한 모델 순서 재정렬 + let arrangedModel = [model.ranking[1], model.ranking[0], model.ranking[2]] + let sentences = arrangedModel.map { $0.sentence } + self.setSpeechBalloonViews(sentences: sentences) + self.setChartData(chartRectangleModel: arrangedModel) + } + + private func setSpeechBalloonViews(sentences: [String]) { + + // 말풍선 text 설정 for (index, sentence) in sentences.enumerated() { var baloonView: SpeechBalloonView if index == 0 { @@ -129,4 +138,12 @@ extension RankingChartCVC { } } } + + private func setChartData(chartRectangleModel: [RankingModel]) { + for (index, rectangle) in chartStackView.subviews.enumerated() { + guard let chartRectangle = rectangle as? ChartRectangleView else { return } + chartRectangle.setData(score: chartRectangleModel[index].score, + username: chartRectangleModel[index].username) + } + } } diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift index 77e0feca..1753035d 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift @@ -89,8 +89,16 @@ extension RankingVC { extension RankingVC { private func bindViewModels() { - let input = RankingViewModel.Input() + let input = RankingViewModel.Input(viewDidLoad: Driver.just(())) + let output = self.viewModel.transform(from: input, cancelBag: self.cancelBag) + + output.$rankingListModel + .dropFirst() + .withUnretained(self) + .sink { owner, model in + owner.applySnapshot(model: model) + }.store(in: self.cancelBag) } private func setDelegate() { @@ -115,7 +123,7 @@ extension RankingVC { case .list: guard let rankingListCell = collectionView.dequeueReusableCell(withReuseIdentifier: RankingListCVC.className, for: indexPath) as? RankingListCVC, let rankingListCellModel = itemIdentifier as? RankingModel else { return UICollectionViewCell() } - rankingListCell.setData(model: rankingListCellModel, rank: indexPath.row + 1) + rankingListCell.setData(model: rankingListCellModel, rank: indexPath.row + 1 + 3) return rankingListCell } diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/ViewModel/RankingViewModel.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/ViewModel/RankingViewModel.swift index dc1d5690..9c168929 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/ViewModel/RankingViewModel.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/ViewModel/RankingViewModel.swift @@ -12,24 +12,24 @@ import Core import Domain public class RankingViewModel: ViewModelType { - + private let useCase: RankingUseCase private var cancelBag = CancelBag() - + // MARK: - Inputs public struct Input { - + let viewDidLoad: Driver } // MARK: - Outputs - public struct Output { - + public class Output { + @Published var rankingListModel = [RankingModel]() } // MARK: - init - + public init(useCase: RankingUseCase) { self.useCase = useCase } @@ -39,12 +39,23 @@ extension RankingViewModel { public func transform(from input: Input, cancelBag: CancelBag) -> Output { let output = Output() self.bindOutput(output: output, cancelBag: cancelBag) - // input,output 상관관계 작성 - + + input.viewDidLoad + .withUnretained(self) + .sink { owner, _ in + owner.useCase.fetchRankingList() + }.store(in: self.cancelBag) + return output } - - private func bindOutput(output: Output, cancelBag: CancelBag) { + private func bindOutput(output: Output, cancelBag: CancelBag) { + let fetchedRankingList = self.useCase.rankingListModelFetched + + fetchedRankingList.asDriver() + .sink(receiveValue: { model in + output.rankingListModel = model + }) + .store(in: self.cancelBag) } } From d2abc5757e8f027cb27860e6750938563abf6c10 Mon Sep 17 00:00:00 2001 From: L-j-h-c Date: Thu, 22 Dec 2022 21:52:37 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[Feat]=20#54=20-=20=EB=9E=AD=ED=82=B9=20?= =?UTF-8?q?=EB=AF=B8=EC=85=98=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EB=B7=B0?= =?UTF-8?q?=EB=A1=9C=20=ED=99=94=EB=A9=B4=EC=A0=84=ED=99=98=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/Sources/Model/RankingModel.swift | 4 ++-- .../RankingScene/Cells/RankingChartCVC.swift | 6 ++++++ .../RankingScene/Cells/RankingListCVC.swift | 12 ++++++++++++ .../Cells/RankingListTappable.swift | 19 +++++++++++++++++++ .../Sources/RankingScene/VC/RankingVC.swift | 17 +++++++++-------- 5 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListTappable.swift diff --git a/SOPT-Stamp-iOS/Projects/Domain/Sources/Model/RankingModel.swift b/SOPT-Stamp-iOS/Projects/Domain/Sources/Model/RankingModel.swift index 38335cee..286de8ae 100644 --- a/SOPT-Stamp-iOS/Projects/Domain/Sources/Model/RankingModel.swift +++ b/SOPT-Stamp-iOS/Projects/Domain/Sources/Model/RankingModel.swift @@ -10,13 +10,13 @@ import Foundation public struct RankingModel: Hashable { public let username: String - public let usreId: Int + public let userId: Int public let score: Int public let sentence: String public init(username: String, usreId: Int, score: Int, sentence: String) { self.username = username - self.usreId = usreId + self.userId = usreId self.score = score self.sentence = sentence } diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift index 0486113e..337e6133 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingChartCVC.swift @@ -147,3 +147,9 @@ extension RankingChartCVC { } } } + +extension RankingChartCVC: RankingListTappble { + func getModelItem() -> RankingListTapItem? { + return RankingListTapItem.init(username: "유저", sentence: "한마디", userId: 1) + } +} diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListCVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListCVC.swift index a3fc2f12..ba0d069d 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListCVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListCVC.swift @@ -21,6 +21,8 @@ final class RankingListCVC: UICollectionViewCell, UICollectionViewRegisterable { static var isFromNib: Bool = false + private var model: RankingModel? + // MARK: - UI Components private let rankLabel: UILabel = { @@ -117,6 +119,7 @@ extension RankingListCVC { extension RankingListCVC { public func setData(model: RankingModel, rank: Int) { + self.model = model rankLabel.text = String(rank) usernameLabel.text = model.username sentenceLabel.text = model.sentence @@ -125,3 +128,12 @@ extension RankingListCVC { font: DSKitFontFamily.Pretendard.medium.font(size: 12)) } } + +extension RankingListCVC: RankingListTappble { + func getModelItem() -> RankingListTapItem? { + guard let model = model else { return nil } + return RankingListTapItem.init(username: model.username, + sentence: model.sentence, + userId: model.userId) + } +} diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListTappable.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListTappable.swift new file mode 100644 index 00000000..dcaa8da7 --- /dev/null +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/Cells/RankingListTappable.swift @@ -0,0 +1,19 @@ +// +// RankingListTappable.swift +// Presentation +// +// Created by Junho Lee on 2022/12/22. +// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. +// + +import Foundation + +protocol RankingListTappble { + func getModelItem() -> RankingListTapItem? +} + +public struct RankingListTapItem { + public let username: String + public let sentence: String + public let userId: Int +} diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift index 1753035d..1030a054 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift @@ -152,14 +152,15 @@ extension RankingVC { extension RankingVC: UICollectionViewDelegate { public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { -// guard let tappedCell = collectionView.cellForItem(at: indexPath) as? MissionListCVC, -// let model = tappedCell.model, -// let starLevel = StarViewLevel.init(rawValue: model.level)else { return } -// let sceneType = model.toListDetailSceneType() - - let otherUserMissionListVC = factory.makeMissionListVC(sceneType: .ranking(userName: "유저", - sentence: "한마디입니다", - userId: 2)) + guard let tappedCell = collectionView.cellForItem(at: indexPath) as? RankingListTappble, + let item = tappedCell.getModelItem() else { return } + self.pushToOtherUserMissionListVC(item: item) + } + + private func pushToOtherUserMissionListVC(item: RankingListTapItem) { + let otherUserMissionListVC = factory.makeMissionListVC(sceneType: .ranking(userName: item.username, + sentence: item.sentence, + userId: item.userId)) self.navigationController?.pushViewController(otherUserMissionListVC, animated: true) } } From 73833758ceb2811b493cb9e32c5b43192c19efc2 Mon Sep 17 00:00:00 2001 From: L-j-h-c Date: Thu, 22 Dec 2022 21:59:46 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[Feat]=20#54=20-=20=EB=A6=AC=ED=94=84?= =?UTF-8?q?=EB=A0=88=EC=8B=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/RankingScene/VC/RankingVC.swift | 17 ++++++++++------- .../ViewModel/RankingViewModel.swift | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift index 1030a054..40392c47 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/VC/RankingVC.swift @@ -38,7 +38,6 @@ public class RankingVC: UIViewController { cv.showsVerticalScrollIndicator = true cv.backgroundColor = .white cv.refreshControl = refresher - refresher.addTarget(self, action: #selector(fetchData(_:)), for: .valueChanged) return cv }() @@ -89,7 +88,13 @@ extension RankingVC { extension RankingVC { private func bindViewModels() { - let input = RankingViewModel.Input(viewDidLoad: Driver.just(())) + let refreshStarted = refresher.publisher(for: .valueChanged) + .map { _ in () } + .eraseToAnyPublisher() + .asDriver() + + let input = RankingViewModel.Input(viewDidLoad: Driver.just(()), + refreshStarted: refreshStarted) let output = self.viewModel.transform(from: input, cancelBag: self.cancelBag) @@ -98,6 +103,7 @@ extension RankingVC { .withUnretained(self) .sink { owner, model in owner.applySnapshot(model: model) + owner.endRefresh() }.store(in: self.cancelBag) } @@ -142,11 +148,8 @@ extension RankingVC { self.view.setNeedsLayout() } - @objc - private func fetchData(_ sender: Any) { - DispatchQueue.main.asyncAfter(deadline: .now()+1.5) { - self.refresher.endRefreshing() - } + private func endRefresh() { + self.refresher.endRefreshing() } } diff --git a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/ViewModel/RankingViewModel.swift b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/ViewModel/RankingViewModel.swift index 9c168929..574a7da7 100644 --- a/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/ViewModel/RankingViewModel.swift +++ b/SOPT-Stamp-iOS/Projects/Presentation/Sources/RankingScene/ViewModel/RankingViewModel.swift @@ -20,6 +20,7 @@ public class RankingViewModel: ViewModelType { public struct Input { let viewDidLoad: Driver + let refreshStarted: Driver } // MARK: - Outputs @@ -40,7 +41,7 @@ extension RankingViewModel { let output = Output() self.bindOutput(output: output, cancelBag: cancelBag) - input.viewDidLoad + input.viewDidLoad.merge(with: input.refreshStarted) .withUnretained(self) .sink { owner, _ in owner.useCase.fetchRankingList()