Skip to content

Commit

Permalink
🪛[chore] : 모듈 분리 작업
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy-wonji committed Nov 4, 2023
1 parent 53cc84f commit 0765423
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 41 deletions.
1 change: 1 addition & 0 deletions PingPong/Projects/Feature/Home/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let project = Project.makeAppModule(
.core(implements: .Authorization),
.core(implements: .Common),
.feature(implements: .Bake),
.feature(implements: .Search),

.SPM.PopupView,
.SPM.Inject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import DesignSystem
import Foundation
import Model
import SwiftUI
import Search

public struct ModalView: View {
let config: SheetManager.Config
let isPopup: Bool
let defaultYoffset: CGFloat

@StateObject private var viewModel: CommonViewViewModel
@StateObject var exploreViewViewModel: ExploreViewModel = ExploreViewModel()


let didClose: () -> Void

Expand Down Expand Up @@ -177,6 +180,24 @@ private extension ModalView {
let flavorParameter: [String] = generateParameter(searchType: .flavor)
let sourceParameter: [String] = generateParameter(searchType: .source)
print(situationParameter, flavorParameter, sourceParameter, viewModel.exploreViewSearchBarText)

Task {
await exploreViewViewModel.searchRequest(keyword: viewModel.exploreViewSearchBarText, flavors: flavorParameter, sources: sourceParameter, mood: situationParameter, orderBy: "") {
viewModel.searchedCards = []

for quoteContent in exploreViewViewModel.searchModel?.data?.content ?? [] {
let hashTags = viewModel.getHashtags(post: quoteContent)
self.viewModel.likeYn = quoteContent.likeYn ?? false
let card = CardInfomation(qouteId: quoteContent.quoteID ?? .zero,
hashtags: hashTags, image: "",
title: quoteContent.content ?? "",
sources: quoteContent.author ?? "",
isBookrmark: quoteContent.likeYn ?? false)
viewModel.searchedCards.append(card)
}
}
}

didClose()
}
}
Expand Down
85 changes: 45 additions & 40 deletions PingPong/Projects/Feature/Search/Sources/UI/View/ExploreView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,11 @@ public struct ExploreView: View {
searchBar()
.padding(.top, 62)

VStack {
HStack {
HStack {

ForEach(viewModel.searchViewButtonInfoArray.indices, id: \.self) { idx in

// TODO: 버튼 정보 예: 맛 + 3 이런 식으로 처리하기
// let info: OptionButtonInfo = exploreViewViewModel.optionButtonInfoArray[idx]
let info = viewModel.searchViewButtonInfoArray[idx]

Button(action: {
withAnimation {
sheetManager.present(with: .init(idx: idx))
}
sheetManager.isPopup = true
}) {

Text(info.count == 0 ? "\(viewModel.searchViewButtonInfoArray[idx].title.rawValue)" : "\(info.choicedTitle)")
.foregroundColor(.cardTextMain)
.pretendardFont(family: .SemiBold, size: 14)
.frame(minWidth: 48, minHeight: 30)
.padding(.horizontal, 8)
.background(
RoundedRectangle(cornerRadius: 8)
.foregroundColor(info.count == 0 ? .primaryOrangeBright: .primaryOrangeOpacity40)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(info.count == 0 ? Color.hotIconBG : .primaryOrange, lineWidth: 1)
)
)
}
}
}.padding(EdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 0))

Spacer()
}
}
.frame(height:46)
searchHashTagView()

staticsView(count: exploreViewViewModel.searchModel?.data?.totalElements ?? .zero)
staticsView(count: viewModel.searchedCards.count)

if !viewModel.cards.isEmpty {
if !viewModel.searchedCards.isEmpty {
searchTextisEmptyQuote

} else {
Expand Down Expand Up @@ -220,6 +183,48 @@ public struct ExploreView: View {
.frame(height: UIScreen.main.bounds.height * 0.56)
}

@ViewBuilder
private func searchHashTagView() -> some View {
VStack {
HStack {
HStack {

ForEach(viewModel.searchViewButtonInfoArray.indices, id: \.self) { idx in

// TODO: 버튼 정보 예: 맛 + 3 이런 식으로 처리하기
// let info: OptionButtonInfo = exploreViewViewModel.optionButtonInfoArray[idx]
let info = viewModel.searchViewButtonInfoArray[idx]

Button(action: {
withAnimation {
sheetManager.present(with: .init(idx: idx))
}
sheetManager.isPopup = true
}) {

Text(info.count == 0 ? "\(viewModel.searchViewButtonInfoArray[idx].title.rawValue)" : "\(info.choicedTitle)")
.foregroundColor(.cardTextMain)
.pretendardFont(family: .SemiBold, size: 14)
.frame(minWidth: 48, minHeight: 30)
.padding(.horizontal, 8)
.background(
RoundedRectangle(cornerRadius: 8)
.foregroundColor(info.count == 0 ? .primaryOrangeBright: .primaryOrangeOpacity40)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(info.count == 0 ? Color.hotIconBG : .primaryOrange, lineWidth: 1)
)
)
}
}
}.padding(EdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 0))

Spacer()
}
}
.frame(height:46)
}

@ViewBuilder
private func staticsView(count: Int) -> some View {
HStack{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import API

public class ExploreViewModel: ObservableObject {

@Published var searchModel: SearchQuoteModel?
@Published public var searchModel: SearchQuoteModel?
var searchCancellable: AnyCancellable?

@Published public var optionButtonInfoArray: [OptionButtonInfo] = [OptionButtonInfo(defaultTitle: .situation),
Expand Down

0 comments on commit 0765423

Please sign in to comment.