77import Foundation
88
99import ComposableArchitecture
10+ import FeatureContentCard
1011import Domain
1112import CoreKit
1213import 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
0 commit comments