Skip to content

Commit

Permalink
[feat] #152 SearchFeature에 ContentCard 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
ShapeKim98 committed Nov 18, 2024
1 parent 95aa852 commit 3aa29e4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import Foundation

import ComposableArchitecture
import FeatureContentCard
import Domain
import CoreKit
import DSKit
Expand Down Expand Up @@ -45,14 +46,7 @@ public struct PokitSearchFeature {
get { domain.condition.searchWord }
set { domain.condition.searchWord = newValue }
}
var resultList: IdentifiedArrayOf<BaseContentItem>? {
guard let contentList = domain.contentList.data else {
return nil
}
var identifiedArray = IdentifiedArrayOf<BaseContentItem>()
contentList.forEach { identifiedArray.append($0) }
return identifiedArray
}
var contents: IdentifiedArrayOf<ContentCardFeature.State> = []
var favoriteFilter: Bool {
get { domain.condition.favorites }
set { domain.condition.favorites = newValue }
Expand All @@ -77,6 +71,7 @@ public struct PokitSearchFeature {
var hasNext: Bool {
get { domain.contentList.hasNext }
}
var isLoading: Bool = false

/// sheet item
var bottomSheetItem: BaseContentItem? = nil
Expand All @@ -92,6 +87,7 @@ public struct PokitSearchFeature {
case scope(ScopeAction)
case delegate(DelegateAction)
case fiterBottomSheet(PresentationAction<FilterBottomFeature.Action>)
case contents(IdentifiedActionOf<ContentCardFeature>)

@CasePathable
public enum View: Equatable, BindableAction {
Expand Down Expand Up @@ -150,12 +146,13 @@ public struct PokitSearchFeature {
case 클립보드_감지
}

public enum ScopeAction: Equatable {
public enum ScopeAction {
case filterBottomSheet(FilterBottomFeature.Action.DelegateAction)
case bottomSheet(
delegate: PokitBottomSheet.Delegate,
content: BaseContentItem
)
case contents(IdentifiedActionOf<ContentCardFeature>)
}

public enum DelegateAction: Equatable {
Expand Down Expand Up @@ -193,13 +190,19 @@ public struct PokitSearchFeature {

case .fiterBottomSheet:
return .none

case .contents(let contentsAction):
return .send(.scope(.contents(contentsAction)))
}
}
public enum CancelID { case response }
/// - Reducer body
public var body: some ReducerOf<Self> {
BindingReducer(action: \.view)
Reduce(self.core)
.forEach(\.contents, action: \.contents) {
ContentCardFeature()
}
.ifLet(\.$filterBottomSheet, action: \.fiterBottomSheet) {
FilterBottomFeature()
}
Expand Down Expand Up @@ -409,6 +412,11 @@ private extension PokitSearchFeature {

case .컨텐츠_검색_API_반영(let contentList):
state.domain.contentList = contentList

var contents = IdentifiedArrayOf<ContentCardFeature.State>()
contentList.data?.forEach { contents.append(.init(content: $0)) }
state.contents = contents
state.isLoading = false
return .send(.inner(.검색창_활성화(true)))

case .최근검색어_불러오기:
Expand All @@ -435,6 +443,7 @@ private extension PokitSearchFeature {
case let .컨텐츠_삭제_API_반영(id):
state.alertItem = nil
state.domain.contentList.data?.removeAll { $0.id == id }
state.contents.removeAll { $0.content.id == id }
return .none

case let .컨텐츠_검색_페이징_API_반영(contentList):
Expand All @@ -443,11 +452,16 @@ private extension PokitSearchFeature {

state.domain.contentList = contentList
state.domain.contentList.data = list + newList

newList.forEach { state.contents.append(.init(content: $0)) }

return .send(.inner(.검색창_활성화(true)))

case .페이징_초기화:
state.domain.pageable.page = 0
state.domain.contentList.data = nil
state.isLoading = true
state.contents.removeAll()
return .send(.async(.컨텐츠_검색_API), animation: .pokitDissolve)
}
}
Expand Down Expand Up @@ -515,6 +529,8 @@ private extension PokitSearchFeature {
pageableRequest,
conditionRequest
).toDomain()

await send(.inner(.컨텐츠_검색_페이징_API_반영(contentList)))
}

case .클립보드_감지:
Expand Down Expand Up @@ -559,6 +575,14 @@ private extension PokitSearchFeature {
state.shareSheetItem = content
return .none
}

case let .contents(.element(id: _, action: .delegate(.컨텐츠_항목_눌렀을때(content)))):
return .send(.delegate(.linkCardTapped(content: content)))
case let .contents(.element(id: _, action: .delegate(.컨텐츠_항목_케밥_버튼_눌렀을때(content)))):
state.bottomSheetItem = content
return .none
case .contents:
return .none
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import SwiftUI

import ComposableArchitecture
import FeatureContentCard
import DSKit

@ViewAction(for: PokitSearchFeature.self)
Expand Down Expand Up @@ -290,19 +291,20 @@ private extension PokitSearchView {
.contentTransition(.numericText())
.padding(.horizontal, 20)

if let results = store.resultList {
if !store.isLoading {
ScrollView {
LazyVStack(spacing: 0) {
ForEach(results, id: \.id) { content in
let isFirst = content == results.first
let isLast = content == results.last
ForEachStore(
store.scope(state: \.contents, action: \.contents)
) { store in
let isFirst = store.state.id == self.store.contents.first?.id
let isLast = store.state.id == self.store.contents.last?.id

PokitLinkCard(
link: content,
action: { send(.컨텐츠_항목_눌렀을때(content: content)) },
kebabAction: { send(.컨텐츠_항목_케밥_버튼_눌렀을때(content: content)) }
ContentCardView(
store: store,
isFirst: isFirst,
isLast: isLast
)
.divider(isFirst: isFirst, isLast: isLast)
}

if store.hasNext {
Expand Down

0 comments on commit 3aa29e4

Please sign in to comment.