Skip to content

Commit 66ff07a

Browse files
committed
[feat] #152 PokitRoot에 ContentCard 적용
1 parent 3bb4158 commit 66ff07a

File tree

2 files changed

+48
-25
lines changed

2 files changed

+48
-25
lines changed

Projects/Feature/FeaturePokit/Sources/PokitRootFeature.swift

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by 김민호 on 7/16/24.
66

77
import ComposableArchitecture
8+
import FeatureContentCard
89
import Domain
910
import CoreKit
1011
import DSKit
@@ -36,16 +37,7 @@ public struct PokitRootFeature {
3637
}
3738
return identifiedArray
3839
}
39-
var unclassifiedContents: IdentifiedArrayOf<BaseContentItem>? {
40-
guard let unclassifiedContentList = domain.unclassifiedContentList.data else {
41-
return nil
42-
}
43-
var identifiedArray = IdentifiedArrayOf<BaseContentItem>()
44-
unclassifiedContentList.forEach { content in
45-
identifiedArray.append(content)
46-
}
47-
return identifiedArray
48-
}
40+
var contents: IdentifiedArrayOf<ContentCardFeature.State> = []
4941

5042
var selectedKebobItem: BaseCategoryItem?
5143
var selectedUnclassifiedItem: BaseContentItem?
@@ -56,6 +48,7 @@ public struct PokitRootFeature {
5648

5749
var hasNext: Bool { domain.categoryList.hasNext }
5850
var unclassifiedHasNext: Bool { domain.unclassifiedContentList.hasNext }
51+
var isLoading: Bool = true
5952

6053
public init() { }
6154
}
@@ -67,6 +60,7 @@ public struct PokitRootFeature {
6760
case async(AsyncAction)
6861
case scope(ScopeAction)
6962
case delegate(DelegateAction)
63+
case contents(IdentifiedActionOf<ContentCardFeature>)
7064

7165
@CasePathable
7266
public enum View: BindableAction, Equatable {
@@ -112,9 +106,10 @@ public struct PokitRootFeature {
112106
case 미분류_카테고리_컨텐츠_삭제_API(contentId: Int)
113107
}
114108

115-
public enum ScopeAction: Equatable {
109+
public enum ScopeAction {
116110
case bottomSheet(PokitBottomSheet.Delegate)
117111
case deleteBottomSheet(PokitDeleteBottomSheet.Delegate)
112+
case contents(IdentifiedActionOf<ContentCardFeature>)
118113
}
119114

120115
public enum DelegateAction: Equatable {
@@ -156,13 +151,20 @@ public struct PokitRootFeature {
156151
/// - Delegate
157152
case .delegate(let delegateAction):
158153
return handleDelegateAction(delegateAction, state: &state)
154+
155+
case .contents(let contentsAciton):
156+
return .send(.scope(.contents(contentsAciton)))
159157
}
160158
}
161159

162160
/// - Reducer body
163161
public var body: some ReducerOf<Self> {
164162
BindingReducer(action: \.view)
165163
Reduce(self.core)
164+
.forEach(\.contents, action: \.contents) {
165+
ContentCardFeature()
166+
}
167+
166168
}
167169
}
168170
//MARK: - FeatureAction Effect
@@ -279,6 +281,12 @@ private extension PokitRootFeature {
279281

280282
case .미분류_카테고리_조회_API_반영(contentList: let contentList):
281283
state.domain.unclassifiedContentList = contentList
284+
285+
var contents = IdentifiedArrayOf<ContentCardFeature.State>()
286+
contentList.data?.forEach { contents.append(.init(content: $0)) }
287+
state.contents = contents
288+
289+
state.isLoading = false
282290
return .none
283291

284292
case let .카테고리_조회_API_반영(categoryList):
@@ -301,20 +309,26 @@ private extension PokitRootFeature {
301309
state.domain.unclassifiedContentList = contentList
302310
state.domain.unclassifiedContentList.data = list + newList
303311
state.domain.pageable.size = 10
312+
newList.forEach { content in
313+
state.contents.append(.init(content: content))
314+
}
304315
return .none
305316

306317
case let .미분류_카테고리_컨텐츠_삭제_API_반영(contentId: contentId):
307318
guard let index = state.domain.unclassifiedContentList.data?.firstIndex(where: { $0.id == contentId }) else {
308319
return .none
309320
}
310321
state.domain.unclassifiedContentList.data?.remove(at: index)
322+
state.contents.removeAll { $0.content.id == contentId }
311323
state.isPokitDeleteSheetPresented = false
312324
return .none
313325

314326
case .페이지네이션_초기화:
315327
state.domain.pageable.page = 0
316328
state.domain.categoryList.data = nil
317329
state.domain.unclassifiedContentList.data = nil
330+
state.isLoading = true
331+
state.contents.removeAll()
318332

319333
switch state.folderType {
320334
case .folder(.포킷):
@@ -525,6 +539,14 @@ private extension PokitRootFeature {
525539
default: return .none
526540
}
527541

542+
case let .contents(.element(id: _, action: .delegate(.컨텐츠_항목_눌렀을때(content)))):
543+
return .send(.delegate(.contentDetailTapped(content)))
544+
case let .contents(.element(id: _, action: .delegate(.컨텐츠_항목_케밥_버튼_눌렀을때(content)))):
545+
state.selectedUnclassifiedItem = content
546+
return .send(.inner(.카테고리_시트_활성화(true)))
547+
case .contents:
548+
return .none
549+
528550
default: return .none
529551
}
530552
}

Projects/Feature/FeaturePokit/Sources/PokitRootView.swift

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import SwiftUI
88

99
import ComposableArchitecture
10+
import FeatureContentCard
1011
import Domain
1112
import DSKit
1213

@@ -166,8 +167,8 @@ private extension PokitRootView {
166167

167168
var unclassifiedView: some View {
168169
Group {
169-
if let unclassifiedContents = store.unclassifiedContents {
170-
if unclassifiedContents.isEmpty {
170+
if !store.isLoading {
171+
if store.contents.isEmpty {
171172
VStack {
172173
PokitCaution(
173174
image: .empty,
@@ -179,28 +180,28 @@ private extension PokitRootView {
179180
Spacer()
180181
}
181182
} else {
182-
unclassifiedList(unclassifiedContents)
183+
unclassifiedList
183184
}
184185
} else {
185186
PokitLoading()
186187
}
187188
}
188189
}
189190

190-
@ViewBuilder
191-
func unclassifiedList(_ unclassifiedContents: IdentifiedArrayOf<BaseContentItem>) -> some View {
191+
var unclassifiedList: some View {
192192
ScrollView {
193193
LazyVStack(spacing: 0) {
194-
ForEach(unclassifiedContents) { content in
195-
let isFirst = content == unclassifiedContents.first
196-
let isLast = content == unclassifiedContents.last
197-
198-
PokitLinkCard(
199-
link: content,
200-
action: { send(.컨텐츠_항목_눌렀을때(content)) },
201-
kebabAction: { send(.미분류_케밥_버튼_눌렀을때(content)) }
194+
ForEachStore(
195+
store.scope(state: \.contents, action: \.contents)
196+
) { store in
197+
let isFirst = store.state.id == self.store.contents.first?.id
198+
let isLast = store.state.id == self.store.contents.last?.id
199+
200+
ContentCardView(
201+
store: store,
202+
isFirst: isFirst,
203+
isLast: isLast
202204
)
203-
.divider(isFirst: isFirst, isLast: isLast)
204205
}
205206

206207
if store.unclassifiedHasNext {

0 commit comments

Comments
 (0)