77import Foundation
88
99import ComposableArchitecture
10+ import FeatureContentCard
1011import Domain
1112import CoreKit
1213import DSKit
@@ -45,14 +46,7 @@ public struct PokitSearchFeature {
4546 get { domain. condition. searchWord }
4647 set { domain. condition. searchWord = newValue }
4748 }
48- var resultList : IdentifiedArrayOf < BaseContentItem > ? {
49- guard let contentList = domain. contentList. data else {
50- return nil
51- }
52- var identifiedArray = IdentifiedArrayOf < BaseContentItem > ( )
53- contentList. forEach { identifiedArray. append ( $0) }
54- return identifiedArray
55- }
49+ var contents : IdentifiedArrayOf < ContentCardFeature . State > = [ ]
5650 var favoriteFilter : Bool {
5751 get { domain. condition. favorites }
5852 set { domain. condition. favorites = newValue }
@@ -77,6 +71,7 @@ public struct PokitSearchFeature {
7771 var hasNext : Bool {
7872 get { domain. contentList. hasNext }
7973 }
74+ var isLoading : Bool = false
8075
8176 /// sheet item
8277 var bottomSheetItem : BaseContentItem ? = nil
@@ -92,6 +87,7 @@ public struct PokitSearchFeature {
9287 case scope( ScopeAction )
9388 case delegate( DelegateAction )
9489 case fiterBottomSheet( PresentationAction < FilterBottomFeature . Action > )
90+ case contents( IdentifiedActionOf < ContentCardFeature > )
9591
9692 @CasePathable
9793 public enum View : Equatable , BindableAction {
@@ -150,12 +146,13 @@ public struct PokitSearchFeature {
150146 case 클립보드_감지
151147 }
152148
153- public enum ScopeAction : Equatable {
149+ public enum ScopeAction {
154150 case filterBottomSheet( FilterBottomFeature . Action . DelegateAction )
155151 case bottomSheet(
156152 delegate: PokitBottomSheet . Delegate ,
157153 content: BaseContentItem
158154 )
155+ case contents( IdentifiedActionOf < ContentCardFeature > )
159156 }
160157
161158 public enum DelegateAction : Equatable {
@@ -193,13 +190,19 @@ public struct PokitSearchFeature {
193190
194191 case . fiterBottomSheet:
195192 return . none
193+
194+ case . contents( let contentsAction) :
195+ return . send( . scope( . contents( contentsAction) ) )
196196 }
197197 }
198198 public enum CancelID { case response }
199199 /// - Reducer body
200200 public var body : some ReducerOf < Self > {
201201 BindingReducer ( action: \. view)
202202 Reduce ( self . core)
203+ . forEach ( \. contents, action: \. contents) {
204+ ContentCardFeature ( )
205+ }
203206 . ifLet ( \. $filterBottomSheet, action: \. fiterBottomSheet) {
204207 FilterBottomFeature ( )
205208 }
@@ -409,6 +412,11 @@ private extension PokitSearchFeature {
409412
410413 case . 컨텐츠_검색_API_반영( let contentList) :
411414 state. domain. contentList = contentList
415+
416+ var contents = IdentifiedArrayOf < ContentCardFeature . State > ( )
417+ contentList. data? . forEach { contents. append ( . init( content: $0) ) }
418+ state. contents = contents
419+ state. isLoading = false
412420 return . send( . inner( . 검색창_활성화( true ) ) )
413421
414422 case . 최근검색어_불러오기:
@@ -435,6 +443,7 @@ private extension PokitSearchFeature {
435443 case let . 컨텐츠_삭제_API_반영( id) :
436444 state. alertItem = nil
437445 state. domain. contentList. data? . removeAll { $0. id == id }
446+ state. contents. removeAll { $0. content. id == id }
438447 return . none
439448
440449 case let . 컨텐츠_검색_페이징_API_반영( contentList) :
@@ -443,11 +452,16 @@ private extension PokitSearchFeature {
443452
444453 state. domain. contentList = contentList
445454 state. domain. contentList. data = list + newList
455+
456+ newList. forEach { state. contents. append ( . init( content: $0) ) }
457+
446458 return . send( . inner( . 검색창_활성화( true ) ) )
447459
448460 case . 페이징_초기화:
449461 state. domain. pageable. page = 0
450462 state. domain. contentList. data = nil
463+ state. isLoading = true
464+ state. contents. removeAll ( )
451465 return . send( . async( . 컨텐츠_검색_API) , animation: . pokitDissolve)
452466 }
453467 }
@@ -515,6 +529,8 @@ private extension PokitSearchFeature {
515529 pageableRequest,
516530 conditionRequest
517531 ) . toDomain ( )
532+
533+ await send ( . inner( . 컨텐츠_검색_페이징_API_반영( contentList) ) )
518534 }
519535
520536 case . 클립보드_감지:
@@ -559,6 +575,14 @@ private extension PokitSearchFeature {
559575 state. shareSheetItem = content
560576 return . none
561577 }
578+
579+ case let . contents( . element( id: _, action: . delegate( . 컨텐츠_항목_눌렀을때( content) ) ) ) :
580+ return . send( . delegate( . linkCardTapped( content: content) ) )
581+ case let . contents( . element( id: _, action: . delegate( . 컨텐츠_항목_케밥_버튼_눌렀을때( content) ) ) ) :
582+ state. bottomSheetItem = content
583+ return . none
584+ case . contents:
585+ return . none
562586 }
563587 }
564588
0 commit comments