Skip to content

Commit

Permalink
Merge pull request #586 from wakmusic/583-refacory-dependency-on-sear…
Browse files Browse the repository at this point in the history
…ch-feature

🔀 :: (#583)  검색 탭의 의존성 관계를 재정의 합니다.
  • Loading branch information
yongbeomkwak authored Jun 12, 2024
2 parents 9e4530b + 07eb3b9 commit 1f416eb
Show file tree
Hide file tree
Showing 34 changed files with 641 additions and 267 deletions.
8 changes: 8 additions & 0 deletions Projects/App/Sources/Application/AppComponent+Search.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ extension AppComponent {
var songSearchResultFactory: any SongSearchResultFactory {
SongSearchResultComponent(parent: self)
}

var listSearchResultFactory: any ListSearchResultFactory {
ListSearchResultComponent(parent: self)
}

var wakmusicRecommendComponent: WakmusicRecommendComponent {
WakmusicRecommendComponent(parent: self)
}
}
39 changes: 36 additions & 3 deletions Projects/App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ private class AfterSearchDependency61822c19bc2eb46d7c52Provider: AfterSearchDepe
var songSearchResultFactory: any SongSearchResultFactory {
return appComponent.songSearchResultFactory
}
var containSongsFactory: any ContainSongsFactory {
return appComponent.containSongsFactory
var listSearchResultFactory: any ListSearchResultFactory {
return appComponent.listSearchResultFactory
}
private let appComponent: AppComponent
init(appComponent: AppComponent) {
Expand All @@ -575,6 +575,22 @@ private class AfterSearchDependency61822c19bc2eb46d7c52Provider: AfterSearchDepe
private func factoryeb2da679e35e2c4fb9a5f47b58f8f304c97af4d5(_ component: NeedleFoundation.Scope) -> AnyObject {
return AfterSearchDependency61822c19bc2eb46d7c52Provider(appComponent: parent1(component) as! AppComponent)
}
private class WakmusicRecommendDependency7d2e1de16b5802ae90ceProvider: WakmusicRecommendDependency {
var fetchRecommendPlayListUseCase: any FetchRecommendPlayListUseCase {
return appComponent.fetchRecommendPlayListUseCase
}
var playlistDetailFactory: any PlaylistDetailFactory {
return appComponent.playlistDetailFactory
}
private let appComponent: AppComponent
init(appComponent: AppComponent) {
self.appComponent = appComponent
}
}
/// ^->AppComponent->WakmusicRecommendComponent
private func factoryaf1c3535530356714983f47b58f8f304c97af4d5(_ component: NeedleFoundation.Scope) -> AnyObject {
return WakmusicRecommendDependency7d2e1de16b5802ae90ceProvider(appComponent: parent1(component) as! AppComponent)
}
private class SearchDependencya86903a2c751a4f762e8Provider: SearchDependency {
var beforeSearchComponent: BeforeSearchComponent {
return appComponent.beforeSearchComponent
Expand Down Expand Up @@ -604,6 +620,9 @@ private class BeforeSearchDependencyebdecb1d478a4766488dProvider: BeforeSearchDe
var textPopUpFactory: any TextPopUpFactory {
return appComponent.textPopUpFactory
}
var wakmusicRecommendComponent: WakmusicRecommendComponent {
return appComponent.wakmusicRecommendComponent
}
private let appComponent: AppComponent
init(appComponent: AppComponent) {
self.appComponent = appComponent
Expand Down Expand Up @@ -1174,7 +1193,18 @@ extension NewSongsContentComponent: Registration {
extension AfterSearchComponent: Registration {
public func registerItems() {
keyPathToName[\AfterSearchDependency.songSearchResultFactory] = "songSearchResultFactory-any SongSearchResultFactory"
keyPathToName[\AfterSearchDependency.containSongsFactory] = "containSongsFactory-any ContainSongsFactory"
keyPathToName[\AfterSearchDependency.listSearchResultFactory] = "listSearchResultFactory-any ListSearchResultFactory"
}
}
extension WakmusicRecommendComponent: Registration {
public func registerItems() {
keyPathToName[\WakmusicRecommendDependency.fetchRecommendPlayListUseCase] = "fetchRecommendPlayListUseCase-any FetchRecommendPlayListUseCase"
keyPathToName[\WakmusicRecommendDependency.playlistDetailFactory] = "playlistDetailFactory-any PlaylistDetailFactory"
}
}
extension ListSearchResultComponent: Registration {
public func registerItems() {

}
}
extension SongSearchResultComponent: Registration {
Expand All @@ -1194,6 +1224,7 @@ extension BeforeSearchComponent: Registration {
keyPathToName[\BeforeSearchDependency.playlistDetailFactory] = "playlistDetailFactory-any PlaylistDetailFactory"
keyPathToName[\BeforeSearchDependency.fetchRecommendPlayListUseCase] = "fetchRecommendPlayListUseCase-any FetchRecommendPlayListUseCase"
keyPathToName[\BeforeSearchDependency.textPopUpFactory] = "textPopUpFactory-any TextPopUpFactory"
keyPathToName[\BeforeSearchDependency.wakmusicRecommendComponent] = "wakmusicRecommendComponent-WakmusicRecommendComponent"
}
}
extension ContainSongsComponent: Registration {
Expand Down Expand Up @@ -1353,6 +1384,8 @@ private func registerProviderFactory(_ componentPath: String, _ factory: @escapi
registerProviderFactory("^->AppComponent->HomeComponent", factory67229cdf0f755562b2b1f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->NewSongsContentComponent", factorye130e1fbfcbc622a4c38f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->AfterSearchComponent", factoryeb2da679e35e2c4fb9a5f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->WakmusicRecommendComponent", factoryaf1c3535530356714983f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->ListSearchResultComponent", factoryEmptyDependencyProvider)
registerProviderFactory("^->AppComponent->SongSearchResultComponent", factoryEmptyDependencyProvider)
registerProviderFactory("^->AppComponent->SearchComponent", factorye3d049458b2ccbbcb3b6f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->BeforeSearchComponent", factory9bb852337d5550979293f47b58f8f304c97af4d5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
reactor: WakmusicRecommendReactor(fetchRecommendPlayListUseCase: fetchPlayListUseCase)
)

let component = SongSearchResultViewController(reactor: SongSearchResultReactor())
let component = SongSearchResultViewController(reactor: SongSearchResultReactor("1234"))
let component2 = ListSearchResultViewController(reactor: ListSearchResultReactor("text"))

let viewController = Inject.ViewControllerHost(
UINavigationController(rootViewController: component)
UINavigationController(rootViewController: component2)
)
window?.rootViewController = viewController
window?.makeKeyAndVisible()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import UIKit

public protocol ListSearchResultFactory {
func makeView(_ text: String) -> UIViewController
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation
import UIKit

public protocol SongSearchResultFactory {
func makeView() -> UIViewController
func makeView(_ text: String) -> UIViewController
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import SongsDomainInterface

public protocol AfterSearchDependency: Dependency {
var songSearchResultFactory: any SongSearchResultFactory { get }
var containSongsFactory: any ContainSongsFactory { get }
var listSearchResultFactory: any ListSearchResultFactory { get }
}

public final class AfterSearchComponent: Component<AfterSearchDependency> {
public func makeView() -> AfterSearchViewController {
public func makeView(text: String) -> AfterSearchViewController {
return AfterSearchViewController.viewController(
songSearchResultFactory: dependency.songSearchResultFactory,
containSongsFactory: dependency.containSongsFactory,
reactor: .init()
listSearchResultFactory: dependency.listSearchResultFactory,
reactor: .init(text: text)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public protocol BeforeSearchDependency: Dependency {
var playlistDetailFactory: any PlaylistDetailFactory { get }
var fetchRecommendPlayListUseCase: any FetchRecommendPlayListUseCase { get }
var textPopUpFactory: any TextPopUpFactory { get }
var wakmusicRecommendComponent: WakmusicRecommendComponent { get }
}

public final class BeforeSearchComponent: Component<BeforeSearchDependency> {
public func makeView() -> BeforeSearchContentViewController {
return BeforeSearchContentViewController(
wakmusicRecommendComponent: dependency.wakmusicRecommendComponent,
textPopUpFactory: dependency.textPopUpFactory,
playlistDetailFactory: dependency.playlistDetailFactory,
reactor: BeforeSearchReactor(fetchRecommendPlayListUseCase: dependency.fetchRecommendPlayListUseCase)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import BaseFeature
import BaseFeatureInterface
import Foundation
import NeedleFoundation
import SearchFeatureInterface
import UIKit

public final class ListSearchResultComponent: Component<EmptyDependency>, ListSearchResultFactory {
public func makeView(_ text: String) -> UIViewController {
ListSearchResultViewController(reactor: ListSearchResultReactor(text))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SearchFeatureInterface
import UIKit

public final class SongSearchResultComponent: Component<EmptyDependency>, SongSearchResultFactory {
public func makeView() -> UIViewController {
SongSearchResultViewController(reactor: SongSearchResultReactor())
public func makeView(_ text: String) -> UIViewController {
SongSearchResultViewController(reactor: SongSearchResultReactor(text))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UIKit

public protocol WakmusicRecommendDependency: Dependency {
var fetchRecommendPlayListUseCase: any FetchRecommendPlayListUseCase { get }
var playlistDetailFacotry: any PlaylistDetailFactory { get }
var playlistDetailFactory: any PlaylistDetailFactory { get }
}

public final class WakmusicRecommendComponent: Component<WakmusicRecommendDependency> {
Expand All @@ -16,7 +16,7 @@ public final class WakmusicRecommendComponent: Component<WakmusicRecommendDepend
)

return WakmusicRecommendViewController(
playlistDetailFactory: dependency.playlistDetailFacotry,
playlistDetailFactory: dependency.playlistDetailFactory,
reactor: reactor
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

internal enum ListSearchResultSection: Hashable {
case list

var title: String {
switch self {
case .list:
"노래"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

internal enum SongSearchResultSection: Int {
case song = 0
internal enum SongSearchResultSection: Hashable {
case song

var title: String {
switch self {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import UIKit
import Utility

final class ListSearchResultCollectionViewLayout: UICollectionViewCompositionalLayout {
init() {
super.init { _, _ in

return ListSearchResultCollectionViewLayout.configureLayout()
}
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension ListSearchResultCollectionViewLayout {
private static func configureLayout() -> NSCollectionLayoutSection {
let itemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(1.0)
)

let headerLayout = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(30))

let header = NSCollectionLayoutBoundarySupplementaryItem(
layoutSize: headerLayout,
elementKind: SearchResultHeaderView.kind,
alignment: .top
)

let item: NSCollectionLayoutItem = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(60.0)
)
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])

let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: .zero, leading: 20.0, bottom: 20.0, trailing: 20.0)
section.boundarySupplementaryItems = [header]

return section
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension SongSearchResultCollectionViewLayout {
let item: NSCollectionLayoutItem = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalWidth(0.16)
heightDimension: .absolute(60.0)
)
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,86 +7,45 @@ import SongsDomainInterface
public final class AfterSearchReactor: Reactor {
var disposeBag: DisposeBag = DisposeBag()

public enum Action {
case updateData(String)
}
private let service: any SearchCommonService

public enum Action {}

public enum Mutation {
case updateData([[Int]])
case updateText(String)
}

public struct State {
var dataSource: [[Int]]
var text: String
}

public var initialState: State

init() {
init(service: some SearchCommonService = DefaultSearchCommonService.shared, text: String) {
self.initialState = State(
dataSource: [],
text: ""
text: text
)
self.service = service
}

deinit {
LogManager.printDebug("\(Self.self)")
}

public func mutate(action: Action) -> Observable<Mutation> {
switch action {
case let .updateData(text):
return fetchData(text)
}
}
public func mutate(action: Action) -> Observable<Mutation> {}

public func reduce(state: State, mutation: Mutation) -> State {
var newState = state

switch mutation {
case let .updateData(data):
newState.dataSource = data
case let .updateText(text):
newState.text = text
}

return newState
}
}

private extension AfterSearchReactor {
func fetchData(_ text: String) -> Observable<Mutation> {
return Observable.just(SearchResultEntity(song: [], artist: [], remix: []))
.asObservable()
.map { res in

let r1 = res.song
let r2 = res.artist
let r3 = res.remix

let limitCount: Int = 3

// let all: [SearchSectionModel] = [
// SearchSectionModel(
// model: (.song, r1.count),
// items: r1.count > limitCount ? Array(r1[0 ... limitCount - 1]) : r1
// ),
// SearchSectionModel(
// model: (.artist, r2.count),
// items: r2.count > limitCount ? Array(r2[0 ... limitCount - 1]) : r2
// ),
// SearchSectionModel(
// model: (.remix, r3.count),
// items: r3.count > limitCount ? Array(r3[0 ... limitCount - 1]) : r3
// )
// ]
//
var results: [[Int]] = []
// results.append(all)
// results.append([SearchSectionModel(model: (.song, r1.count), items: r1)])
// results.append([SearchSectionModel(model: (.artist, r2.count), items: r2)])
// results.append([SearchSectionModel(model: (.remix, r3.count), items: r3)])

return results
}
.map { Mutation.updateData($0) }
}
#warning("유즈케이스 주입")
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class BeforeSearchReactor: Reactor {
self.initialState = State(
showRecommend: true,
dataSource: [],
isLoading: true
isLoading: false
)
}

Expand Down
Loading

0 comments on commit 1f416eb

Please sign in to comment.