77import Foundation
88
99import ComposableArchitecture
10+ import FeatureContentCard
1011import Domain
1112import CoreKit
1213import DSKit
@@ -51,16 +52,7 @@ public struct CategoryDetailFeature {
5152 }
5253 return identifiedArray
5354 }
54- var contents : IdentifiedArrayOf < BaseContentItem > ? {
55- guard let contentList = domain. contentList. data else {
56- return nil
57- }
58- var identifiedArray = IdentifiedArrayOf < BaseContentItem > ( )
59- contentList. forEach { content in
60- identifiedArray. append ( content)
61- }
62- return identifiedArray
63- }
55+ var contents : IdentifiedArrayOf < ContentCardFeature . State > = [ ]
6456 var kebobSelectedType : PokitDeleteBottomSheet . SheetType ?
6557 var selectedContentItem : BaseContentItem ?
6658 var shareSheetItem : BaseContentItem ? = nil
@@ -73,6 +65,7 @@ public struct CategoryDetailFeature {
7365 var hasNext : Bool {
7466 domain. contentList. hasNext
7567 }
68+ var isLoading : Bool = true
7669
7770 public init ( category: BaseCategoryItem ) {
7871 self . domain = . init( categpry: category)
@@ -86,6 +79,7 @@ public struct CategoryDetailFeature {
8679 case async ( AsyncAction )
8780 case scope( ScopeAction )
8881 case delegate( DelegateAction )
82+ case contents( IdentifiedActionOf < ContentCardFeature > )
8983
9084 @CasePathable
9185 public enum View : BindableAction , Equatable {
@@ -121,10 +115,11 @@ public struct CategoryDetailFeature {
121115 case ํด๋ฆฝ๋ณด๋_๊ฐ์ง
122116 }
123117
124- public enum ScopeAction : Equatable {
118+ public enum ScopeAction {
125119 case categoryBottomSheet( PokitBottomSheet . Delegate )
126120 case categoryDeleteBottomSheet( PokitDeleteBottomSheet . Delegate )
127121 case filterBottomSheet( CategoryFilterSheet . Delegate )
122+ case contents( IdentifiedActionOf < ContentCardFeature > )
128123 }
129124
130125 public enum DelegateAction : Equatable {
@@ -163,13 +158,19 @@ public struct CategoryDetailFeature {
163158 /// - Delegate
164159 case . delegate( let delegateAction) :
165160 return handleDelegateAction ( delegateAction, state: & state)
161+
162+ case . contents( let contentsAction) :
163+ return . send( . scope( . contents( contentsAction) ) )
166164 }
167165 }
168166
169167 /// - Reducer body
170168 public var body : some ReducerOf < Self > {
171169 BindingReducer ( action: \. view)
172170 Reduce ( self . core)
171+ . forEach ( \. contents, action: \. contents) {
172+ ContentCardFeature ( )
173+ }
173174 }
174175}
175176//MARK: - FeatureAction Effect
@@ -191,7 +192,7 @@ private extension CategoryDetailFeature {
191192 case . ์นดํ
๊ณ ๋ฆฌ_์ ํํ์๋( let item) :
192193 state. domain. category = item
193194 return . run { send in
194- await send ( . inner( . pagenation_์ด๊ธฐํ) )
195+ await send ( . inner( . pagenation_์ด๊ธฐํ) , animation : . pokitDissolve )
195196 await send ( . async( . ์นดํ
๊ณ ๋ฆฌ_๋ด_์ปจํ
์ธ _๋ชฉ๋ก_์กฐํ_API) )
196197 await send ( . inner( . ์นดํ
๊ณ ๋ฆฌ_์ ํ_์ํธ_ํ์ฑํ( false ) ) )
197198 }
@@ -248,10 +249,17 @@ private extension CategoryDetailFeature {
248249
249250 case . ์นดํ
๊ณ ๋ฆฌ_๋ด_์ปจํ
์ธ _๋ชฉ๋ก_์กฐํ_API_๋ฐ์( let contentList) :
250251 state. domain. contentList = contentList
252+
253+ var identifiedArray = IdentifiedArrayOf < ContentCardFeature . State > ( )
254+ contentList. data? . forEach { identifiedArray. append ( . init( content: $0) ) }
255+ state. contents = identifiedArray
256+
257+ state. isLoading = false
251258 return . none
252259
253260 case let . ์ปจํ
์ธ _์ญ์ _API_๋ฐ์( id) :
254261 state. domain. contentList. data? . removeAll { $0. id == id }
262+ state. contents. removeAll { $0. content. id == id }
255263 state. domain. category. contentCount -= 1
256264 state. selectedContentItem = nil
257265 state. isPokitDeleteSheetPresented = false
@@ -264,11 +272,15 @@ private extension CategoryDetailFeature {
264272
265273 state. domain. contentList = contentList
266274 state. domain. contentList. data = list + newList
275+ newList. forEach { state. contents. append ( . init( content: $0) ) }
276+
267277 return . none
268278
269279 case . pagenation_์ด๊ธฐํ:
270280 state. domain. pageable. page = 0
271281 state. domain. contentList. data = nil
282+ state. isLoading = true
283+ state. contents. removeAll ( )
272284 return . none
273285 }
274286 }
@@ -459,6 +471,15 @@ private extension CategoryDetailFeature {
459471 . send( . async( . ์นดํ
๊ณ ๋ฆฌ_๋ด_์ปจํ
์ธ _๋ชฉ๋ก_์กฐํ_API) )
460472 )
461473 }
474+
475+ case let . contents( . element( id: _, action: . delegate( . ์ปจํ
์ธ _ํญ๋ชฉ_๋๋ ์๋( content) ) ) ) :
476+ return . send( . delegate( . contentItemTapped( content) ) )
477+ case let . contents( . element( id: _, action: . delegate( . ์ปจํ
์ธ _ํญ๋ชฉ_์ผ๋ฐฅ_๋ฒํผ_๋๋ ์๋( content) ) ) ) :
478+ state. kebobSelectedType = . ๋งํฌ์ญ์
479+ state. selectedContentItem = content
480+ return . send( . inner( . ์นดํ
๊ณ ๋ฆฌ_์ํธ_ํ์ฑํ( true ) ) )
481+ case . contents:
482+ return . none
462483 }
463484 }
464485
0 commit comments