Skip to content

Commit 2a54ec7

Browse files
authored
Merge pull request #404 from Team-return/feature/(#403)-Codeseparation_qualityimprovement
🔗 :: (#403) code separation quality improvement
2 parents fa01e14 + 6bb0d40 commit 2a54ec7

19 files changed

+156
-131
lines changed

Projects/Presentation/Sources/Apply/ApplyReactor.swift

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,31 @@ extension ApplyReactor {
7070
public func mutate(action: Action) -> Observable<Mutation> {
7171
switch action {
7272
case let .documentDidAdd(document):
73-
return .just(.addDocument(document))
73+
let newDocuments = currentState.documents + [document]
74+
let isEnabled = !newDocuments.isEmpty || !currentState.urls.isEmpty
75+
return .concat(
76+
.just(.addDocument(document)),
77+
.just(.updateApplyButtonEnabled(isEnabled))
78+
)
7479

7580
case .urlAddButtonDidTap:
76-
return .just(.addUrl)
81+
let newUrls = currentState.urls + [.init(url: "", type: .url)]
82+
let isEnabled = !currentState.documents.isEmpty || !newUrls.isEmpty
83+
return .concat(
84+
.just(.addUrl),
85+
.just(.updateApplyButtonEnabled(isEnabled))
86+
)
7787

7888
case let .urlDidChange(index, url):
79-
return .just(.updateUrl(index, url))
89+
var newUrls = currentState.urls
90+
if index < newUrls.count {
91+
newUrls[index] = .init(url: url, type: .url)
92+
}
93+
let isEnabled = !currentState.documents.isEmpty || !newUrls.isEmpty
94+
return .concat(
95+
.just(.updateUrl(index, url)),
96+
.just(.updateApplyButtonEnabled(isEnabled))
97+
)
8098

8199
case .applyButtonDidTap:
82100
let attachments = currentState.documents + currentState.urls
@@ -111,10 +129,26 @@ extension ApplyReactor {
111129
}
112130

113131
case let .removeUrl(index):
114-
return .just(.removeUrl(index))
132+
var newUrls = currentState.urls
133+
if index < newUrls.count {
134+
newUrls.remove(at: index)
135+
}
136+
let isEnabled = !currentState.documents.isEmpty || !newUrls.isEmpty
137+
return .concat(
138+
.just(.removeUrl(index)),
139+
.just(.updateApplyButtonEnabled(isEnabled))
140+
)
115141

116142
case let .removeDocument(index):
117-
return .just(.removeDocument(index))
143+
var newDocuments = currentState.documents
144+
if index < newDocuments.count {
145+
newDocuments.remove(at: index)
146+
}
147+
let isEnabled = !newDocuments.isEmpty || !currentState.urls.isEmpty
148+
return .concat(
149+
.just(.removeDocument(index)),
150+
.just(.updateApplyButtonEnabled(isEnabled))
151+
)
118152
}
119153
}
120154

@@ -124,7 +158,6 @@ extension ApplyReactor {
124158
switch mutation {
125159
case let .addDocument(document):
126160
newState.documents.append(document)
127-
newState.applyButtonEnabled = !newState.documents.isEmpty || !newState.urls.isEmpty
128161

129162
case .addUrl:
130163
newState.urls.append(.init(url: "", type: .url))
@@ -133,19 +166,16 @@ extension ApplyReactor {
133166
if index < newState.urls.count {
134167
newState.urls[index] = .init(url: url, type: .url)
135168
}
136-
newState.applyButtonEnabled = !newState.documents.isEmpty || !newState.urls.isEmpty
137169

138170
case let .removeUrl(index):
139171
if index < newState.urls.count {
140172
newState.urls.remove(at: index)
141173
}
142-
newState.applyButtonEnabled = !newState.documents.isEmpty || !newState.urls.isEmpty
143174

144175
case let .removeDocument(index):
145176
if index < newState.documents.count {
146177
newState.documents.remove(at: index)
147178
}
148-
newState.applyButtonEnabled = !newState.documents.isEmpty || !newState.urls.isEmpty
149179

150180
case let .updateApplyButtonEnabled(enabled):
151181
newState.applyButtonEnabled = enabled

Projects/Presentation/Sources/Apply/ApplyViewController.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@ public final class ApplyViewController: BaseReactorViewController<ApplyReactor>
4646
private let docsPicker = UIDocumentPickerViewController(forOpeningContentTypes: [
4747
.pdf,
4848
.png,
49-
.jpeg,
50-
.init(filenameExtension: "doc")!,
51-
.init(filenameExtension: "docx")!,
52-
.init(filenameExtension: "hwp")!,
53-
.init(filenameExtension: "pptx")!
54-
])
49+
.jpeg
50+
] + [
51+
"doc", "docx", "hwp", "pptx"
52+
].compactMap { .init(filenameExtension: $0) })
5553

5654
private let documents = PublishRelay<AttachmentsRequestQuery>()
5755
private let urls = BehaviorRelay<[AttachmentsRequestQuery]>(value: [])

Projects/Presentation/Sources/Bookmark/BookmarkViewController.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,18 @@ public final class BookmarkViewController: BaseReactorViewController<BookmarkRea
3030
}
3131

3232
public override func addView() {
33-
[
34-
bookmarkTableView
35-
].forEach(self.view.addSubview(_:))
36-
37-
[
38-
emptyBookmarkView,
39-
navigateToRecruitmentButton
40-
].forEach(self.bookmarkTableView.addSubview(_:))
33+
self.view.addSubview(bookmarkTableView)
34+
self.view.addSubview(emptyBookmarkView)
35+
self.view.addSubview(navigateToRecruitmentButton)
4136
}
4237

4338
public override func setLayout() {
4439
bookmarkTableView.snp.makeConstraints {
45-
$0.topMargin.leading.trailing.bottom.equalToSuperview()
40+
$0.top.leading.trailing.bottom.equalTo(view.safeAreaLayoutGuide)
4641
}
4742

4843
emptyBookmarkView.snp.makeConstraints {
49-
$0.top.equalToSuperview().inset(80)
44+
$0.top.equalTo(view.safeAreaLayoutGuide).inset(80)
5045
$0.centerX.equalToSuperview()
5146
}
5247

@@ -118,6 +113,4 @@ public final class BookmarkViewController: BaseReactorViewController<BookmarkRea
118113
}
119114
.disposed(by: disposeBag)
120115
}
121-
122-
public override func configureNavigation() { }
123116
}

Projects/Presentation/Sources/Home/Components/BannerView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ final class BannerView: BaseView {
7575

7676
public func setPageControl(count: Int) {
7777
self.pageControl.numberOfPages = count
78-
self.pageControl.setIndicatorImage(.jobisIcon(.currentPageControl), forPage: 0)
78+
if count > 0 {
79+
self.pageControl.setIndicatorImage(.jobisIcon(.currentPageControl), forPage: 0)
80+
}
7981
}
8082
}
8183

Projects/Presentation/Sources/Home/Components/Cell/BannerCollectionViewCell.swift

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import SnapKit
44
import Then
55
import DesignSystem
66

7-
final class BannerCollectionViewCell: BaseCollectionViewCell<FetchBannerEntity> {
7+
final class BannerCollectionViewCell: BaseCollectionViewCell<HomeBannerItem> {
88
static let identifier = "BannerCollectionViewCell"
99

10-
private let currentYear = Date()
1110
private let imageView = UIImageView().then {
1211
$0.contentMode = .scaleAspectFill
1312
$0.layer.cornerRadius = 16
1413
$0.clipsToBounds = true
1514
}
1615
private lazy var passTitleLabel = UILabel().then {
1716
$0.numberOfLines = 0
17+
let currentYear = Calendar.current.component(.year, from: Date())
1818
$0.setJobisText(
19-
"\(Int(currentYear.toStringFormat("yyyy"))! - 2016)기 대마고\n학생들의 취업률",
19+
"\(currentYear - 2016)기 대마고\n학생들의 취업률",
2020
font: .headLine,
2121
color: .GrayScale.gray90
2222
)
@@ -81,19 +81,42 @@ final class BannerCollectionViewCell: BaseCollectionViewCell<FetchBannerEntity>
8181
self.backgroundColor = .GrayScale.gray30
8282
}
8383

84-
override func adapt(model: FetchBannerEntity) {
85-
setLayout()
86-
self.imageView.setJobisImage(urlString: model.bannerURL)
87-
}
84+
override func adapt(model: HomeBannerItem) {
85+
switch model {
86+
case let .banner(entity):
87+
// Reset/Setup for Banner
88+
resetViews()
89+
setLayout()
90+
self.imageView.setJobisImage(urlString: entity.bannerURL)
91+
self.imageView.isHidden = false
8892

89-
func totalPassAdapt(model: TotalPassStudentEntity) {
90-
totalPassSetLayout()
91-
let employmentRate = Double(model.passedCount) / Double(model.totalStudentCount) * 100.0
92-
let passText = String(format: "%.1f", employmentRate)
93-
passLabel.setJobisText(
94-
"\(passText)%",
95-
font: .headLine,
96-
color: .Primary.blue20
97-
)
93+
case let .totalPass(entity):
94+
// Reset/Setup for Total Pass
95+
resetViews()
96+
totalPassSetLayout()
97+
let employmentRate = Double(entity.passedCount) / Double(entity.totalStudentCount) * 100.0
98+
let passText = String(format: "%.1f", employmentRate.isNaN ? 0.0 : employmentRate)
99+
passLabel.setJobisText(
100+
"\(passText)%",
101+
font: .headLine,
102+
color: .Primary.blue20
103+
)
104+
105+
passTitleLabel.isHidden = false
106+
passLabel.isHidden = false
107+
employStatusButton.isHidden = false
108+
fileImageView.isHidden = false
109+
}
110+
}
111+
112+
private func resetViews() {
113+
imageView.isHidden = true
114+
passTitleLabel.isHidden = true
115+
passLabel.isHidden = true
116+
employStatusButton.isHidden = true
117+
fileImageView.isHidden = true
118+
119+
// Clear image to prevent reuse issues
120+
imageView.image = nil
98121
}
99122
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Domain
2+
3+
public enum HomeBannerItem {
4+
case totalPass(TotalPassStudentEntity)
5+
case banner(FetchBannerEntity)
6+
}

Projects/Presentation/Sources/Home/HomeReactor.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import RxFlow
66
import Core
77
import Domain
88

9+
import Domain
10+
911
public final class HomeReactor: BaseReactor, Stepper {
1012
public let steps = PublishRelay<Step>()
1113
public let initialState: State
@@ -56,6 +58,9 @@ public final class HomeReactor: BaseReactor, Stepper {
5658
var studentInfo: StudentInfoEntity?
5759
var applicationList: [ApplicationEntity] = []
5860
var bannerList: [FetchBannerEntity] = []
61+
var banners: [HomeBannerItem] = [
62+
.totalPass(.init(totalStudentCount: 0, passedCount: 0, approvedCount: 0))
63+
]
5964
var isWinterInternSeason: Bool = true
6065
var totalPassStudentInfo: TotalPassStudentEntity = TotalPassStudentEntity(
6166
totalStudentCount: 0,
@@ -163,12 +168,14 @@ extension HomeReactor {
163168

164169
case let .setBannerList(bannerList):
165170
newState.bannerList = bannerList
171+
newState.banners = [.totalPass(newState.totalPassStudentInfo)] + bannerList.map { .banner($0) }
166172

167173
case let .setWinterInternSeason(isWinterIntern):
168174
newState.isWinterInternSeason = isWinterIntern
169175

170176
case let .setTotalPassStudentInfo(totalPassStudent):
171177
newState.totalPassStudentInfo = totalPassStudent
178+
newState.banners = [.totalPass(totalPassStudent)] + newState.bannerList.map { .banner($0) }
172179

173180
case .incrementEasterEggCount:
174181
newState.touchedPopcatCount += 1

Projects/Presentation/Sources/Home/HomeViewController.swift

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -197,40 +197,25 @@ public final class HomeViewController: BaseReactorViewController<HomeReactor> {
197197
}
198198
.disposed(by: disposeBag)
199199

200-
let combinedBanners = Observable.combineLatest(
201-
reactor.state.map { $0.totalPassStudentInfo },
202-
reactor.state.map { $0.bannerList }
203-
)
204-
.map { totalPass, banners -> [Any] in
205-
return [totalPass] + banners
206-
}
207-
208-
combinedBanners
200+
reactor.state.map { $0.banners }
209201
.do(onNext: { [weak self] _ in
210202
self?.cellDisposeBag = DisposeBag()
211203
})
212-
.do(onNext: { banners in
213-
self.bannerView.setPageControl(count: banners.count)
204+
.do(onNext: { [weak self] banners in
205+
self?.bannerView.setPageControl(count: banners.count)
214206
})
215207
.bind(to: bannerView.collectionView.rx.items(
216208
cellIdentifier: BannerCollectionViewCell.identifier,
217209
cellType: BannerCollectionViewCell.self
218-
)) { [weak self] index, element, cell in
210+
)) { [weak self] _, element, cell in
219211
guard let self = self else { return }
220-
221-
if index == 0,
222-
let totalPassModel = element as? TotalPassStudentEntity,
223-
let cell = cell as? BannerCollectionViewCell {
224-
cell.totalPassAdapt(model: totalPassModel)
212+
cell.adapt(model: element)
213+
214+
if case .totalPass = element {
225215
cell.employStatusButton.rx.tap
226216
.map { _ in () }
227217
.bind(to: self.employStatusButtonTap)
228218
.disposed(by: self.cellDisposeBag)
229-
} else {
230-
if let fetchBanner = element as? FetchBannerEntity,
231-
let cell = cell as? BannerCollectionViewCell {
232-
cell.adapt(model: fetchBanner)
233-
}
234219
}
235220
}
236221
.disposed(by: disposeBag)

Projects/Presentation/Sources/Recruitment/RecruitmentViewController.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ public final class RecruitmentViewController: BaseReactorViewController<Recruitm
3636

3737
public override func addView() {
3838
self.view.addSubview(recruitmentTableView)
39-
recruitmentTableView.addSubview(listEmptyView)
39+
self.view.addSubview(listEmptyView)
4040
}
4141

4242
public override func setLayout() {
4343
recruitmentTableView.snp.makeConstraints {
44-
$0.edges.equalToSuperview()
44+
$0.top.leading.trailing.bottom.equalTo(view.safeAreaLayoutGuide)
4545
}
4646
listEmptyView.snp.makeConstraints {
4747
$0.centerX.equalToSuperview()
48-
$0.top.equalToSuperview().inset(80)
48+
$0.top.equalTo(view.safeAreaLayoutGuide).inset(80)
4949
}
5050
}
5151

@@ -107,14 +107,17 @@ public final class RecruitmentViewController: BaseReactorViewController<Recruitm
107107

108108
if isLoading {
109109
self.recruitmentTableView.reloadData()
110-
DispatchQueue.main.async {
110+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) { [weak self] in
111+
guard let self = self,
112+
self.reactor.currentState.isLoading else { return }
111113
self.recruitmentTableView.showAnimatedSkeleton(
112114
usingColor: .systemGray5,
113115
transition: .crossDissolve(0.25)
114116
)
115117
}
116118
} else {
117119
self.recruitmentTableView.hideSkeleton(reloadDataAfter: true, transition: .crossDissolve(0.25))
120+
self.listEmptyView.isHidden = !list.isEmpty
118121
}
119122
})
120123
.disposed(by: disposeBag)

Projects/Presentation/Sources/RecruitmentDetail/RecruitmentDetailViewController.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public class RecruitmentDetailViewController: BaseReactorViewController<Recruitm
3636
private let recruitmentProcessLabel = RecruitmentDetailLabel(title: "선발 절차")
3737
private let requiredGradeLabel = RecruitmentDetailLabel(title: "기타 자격 요건")
3838
private let workingHoursLabel = RecruitmentDetailLabel(title: "근무시간")
39-
// private let awardedMoneyLabel = RecruitmentDetailLabel(title: "실습 수당")
40-
// private let permanentEmployeeLabel = RecruitmentDetailLabel(title: "정규직 전환 시")
4139
private let benefitsWelfareLabel = RecruitmentDetailLabel(title: "복리후생")
4240
private let needThingsLabel = RecruitmentDetailLabel(title: "제출 서류")
4341
private let otherMattersLabel = RecruitmentDetailLabel(title: "기타 사항")
@@ -69,8 +67,6 @@ public class RecruitmentDetailViewController: BaseReactorViewController<Recruitm
6967
recruitmentProcessLabel,
7068
requiredGradeLabel,
7169
workingHoursLabel,
72-
// awardedMoneyLabel,
73-
// permanentEmployeeLabel,
7470
benefitsWelfareLabel,
7571
needThingsLabel,
7672
otherMattersLabel
@@ -193,6 +189,4 @@ public class RecruitmentDetailViewController: BaseReactorViewController<Recruitm
193189
}
194190
.disposed(by: disposeBag)
195191
}
196-
197-
public override func configureNavigation() {}
198192
}

0 commit comments

Comments
 (0)