55// Created by 김민호 on 7/16/24.
66
77import ComposableArchitecture
8+ import FeatureContentCard
89import Domain
910import CoreKit
1011import 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 }
0 commit comments