Skip to content

Commit fb0c910

Browse files
committed
[feat] #152 CategorySharing에 ContentCard 적용
1 parent 3febfb5 commit fb0c910

File tree

2 files changed

+72
-23
lines changed

2 files changed

+72
-23
lines changed

Projects/Feature/FeatureCategorySharing/Sources/CategorySharing/CategorySharingFeature.swift

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import Foundation
88

99
import ComposableArchitecture
10+
import FeatureContentCard
1011
import Domain
1112
import CoreKit
1213
import Util
@@ -26,16 +27,11 @@ public struct CategorySharingFeature {
2627
public struct State: Equatable {
2728
fileprivate var domain: CategorySharing
2829
var category: CategorySharing.Category { domain.sharedCategory.category }
29-
var contents: IdentifiedArrayOf<CategorySharing.Content>? {
30-
var identifiedArray = IdentifiedArrayOf<CategorySharing.Content>()
31-
domain.sharedCategory.contentList.data.forEach { content in
32-
identifiedArray.append(content)
33-
}
34-
return identifiedArray
35-
}
30+
var contents: IdentifiedArrayOf<ContentCardFeature.State> = []
3631
var hasNext: Bool { domain.sharedCategory.contentList.hasNext }
3732
var error: BaseError?
3833
var isErrorSheetPresented: Bool = false
34+
var isLoading: Bool = true
3935

4036
public init(sharedCategory: CategorySharing.SharedCategory) {
4137
domain = .init(
@@ -56,16 +52,17 @@ public struct CategorySharingFeature {
5652
case async(AsyncAction)
5753
case scope(ScopeAction)
5854
case delegate(DelegateAction)
55+
case contents(IdentifiedActionOf<ContentCardFeature>)
5956

6057
@CasePathable
6158
public enum View: Equatable, BindableAction {
6259
case binding(BindingAction<State>)
6360
case dismiss
6461

6562
case 저장_버튼_눌렀을때
66-
case 컨텐츠_항목_눌렀을때(CategorySharing.Content)
6763
case 경고_확인버튼_눌렀을때
6864
case 페이지_로딩중일때
65+
case 뷰가_나타났을때
6966
}
7067

7168
public enum InnerAction: Equatable {
@@ -78,7 +75,9 @@ public struct CategorySharingFeature {
7875
case 공유받은_카테고리_조회_API
7976
}
8077

81-
public enum ScopeAction: Equatable { case 없음 }
78+
public enum ScopeAction {
79+
case contents(IdentifiedActionOf<ContentCardFeature>)
80+
}
8281

8382
public enum DelegateAction: Equatable {
8483
case 컨텐츠_아이템_클릭(categoryId: Int, content: CategorySharing.Content)
@@ -111,13 +110,19 @@ public struct CategorySharingFeature {
111110
/// - Delegate
112111
case .delegate(let delegateAction):
113112
return handleDelegateAction(delegateAction, state: &state)
113+
114+
case .contents(let contentsAction):
115+
return .send(.scope(.contents(contentsAction)))
114116
}
115117
}
116118

117119
/// - Reducer body
118120
public var body: some ReducerOf<Self> {
119121
BindingReducer(action: \.view)
120122
Reduce(self.core)
123+
.forEach(\.contents, action: \.contents) {
124+
ContentCardFeature()
125+
}
121126
}
122127
}
123128
//MARK: - FeatureAction Effect
@@ -135,14 +140,27 @@ private extension CategorySharingFeature {
135140
let sharedCategory = state.domain.sharedCategory.category
136141
return .send(.delegate(.공유받은_카테고리_추가(sharedCategory: sharedCategory)))
137142

138-
case let .컨텐츠_항목_눌렀을때(content):
139-
return .send(.delegate(.컨텐츠_아이템_클릭(categoryId: state.category.categoryId , content: content)))
140-
141143
case .경고_확인버튼_눌렀을때:
142144
return .none
143145

144146
case .페이지_로딩중일때:
145147
return .send(.async(.공유받은_카테고리_조회_API))
148+
case .뷰가_나타났을때:
149+
state.domain.sharedCategory.contentList.data.forEach { content in
150+
state.contents.append(.init(content: .init(
151+
id: content.id,
152+
categoryName: content.categoryName,
153+
categoryId: state.category.categoryId,
154+
title: content.title,
155+
thumbNail: content.thumbNail,
156+
data: content.data,
157+
domain: content.domain,
158+
createdAt: content.createdAt,
159+
isRead: content.isRead
160+
)))
161+
}
162+
state.isLoading = false
163+
return .none
146164
}
147165
}
148166

@@ -151,6 +169,21 @@ private extension CategorySharingFeature {
151169
switch action {
152170
case let .공유받은_카테고리_API_반영(sharedCategory):
153171
state.domain.sharedCategory = sharedCategory
172+
173+
sharedCategory.contentList.data.forEach { content in
174+
state.contents.append(.init(content: .init(
175+
id: content.id,
176+
categoryName: content.categoryName,
177+
categoryId: state.category.categoryId,
178+
title: content.title,
179+
thumbNail: content.thumbNail,
180+
data: content.data,
181+
domain: content.domain,
182+
createdAt: content.createdAt,
183+
isRead: content.isRead
184+
)))
185+
}
186+
state.isLoading = false
154187
return .none
155188

156189
case let .경고_띄움(baseError):
@@ -186,7 +219,20 @@ private extension CategorySharingFeature {
186219

187220
/// - Scope Effect
188221
func handleScopeAction(_ action: Action.ScopeAction, state: inout State) -> Effect<Action> {
189-
return .none
222+
switch action {
223+
case let .contents(.element(id: _, action: .delegate(.컨텐츠_항목_눌렀을때(content)))):
224+
let sharedContent = state.domain.sharedCategory.contentList.data.first { item in
225+
item.id == content.id
226+
}
227+
guard let sharedContent else { return .none }
228+
229+
return .send(.delegate(.컨텐츠_아이템_클릭(
230+
categoryId: state.category.categoryId,
231+
content: sharedContent
232+
)))
233+
case .contents:
234+
return .none
235+
}
190236
}
191237

192238
/// - Delegate Effect

Projects/Feature/FeatureCategorySharing/Sources/CategorySharing/CategorySharingView.swift

Lines changed: 13 additions & 10 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

@@ -34,6 +35,7 @@ public extension CategorySharingView {
3435
.padding(.top, 12)
3536
.pokitNavigationBar { navigationBar }
3637
.ignoresSafeArea(edges: .bottom)
38+
.onAppear { send(.뷰가_나타났을때, animation: .pokitDissolve) }
3739
.sheet(isPresented: $store.isErrorSheetPresented) {
3840
PokitAlert(
3941
store.error?.title ?? "에러",
@@ -86,8 +88,8 @@ private extension CategorySharingView {
8688

8789
var contentScrollView: some View {
8890
Group {
89-
if let contents = store.contents {
90-
if contents.isEmpty {
91+
if !store.isLoading {
92+
if store.contents.isEmpty {
9193
VStack {
9294
PokitCaution(
9395
image: .empty,
@@ -101,16 +103,17 @@ private extension CategorySharingView {
101103
} else {
102104
ScrollView(showsIndicators: false) {
103105
LazyVStack(spacing: 0) {
104-
ForEach(contents) { content in
105-
let isFirst = content == contents.first
106-
let isLast = content == contents.last
106+
ForEachStore(
107+
store.scope(state: \.contents, action: \.contents)
108+
) { store in
109+
let isFirst = store.state.id == self.store.contents.first?.id
110+
let isLast = store.state.id == self.store.contents.last?.id
107111

108-
PokitLinkCard(
109-
link: content,
110-
action: { send(.컨텐츠_항목_눌렀을때(content)) }
112+
ContentCardView(
113+
store: store,
114+
isFirst: isFirst,
115+
isLast: isLast
111116
)
112-
.divider(isFirst: isFirst, isLast: isLast)
113-
.pokitScrollTransition(.opacity)
114117
}
115118

116119
if store.hasNext {

0 commit comments

Comments
 (0)