From 0765423d00d0069ed4ba0d3d27b487921fab7833 Mon Sep 17 00:00:00 2001 From: Roy-wonji Date: Sat, 4 Nov 2023 23:23:50 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=9B[chore]=20:=20=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=20=EB=B6=84=EB=A6=AC=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PingPong/Projects/Feature/Home/Project.swift | 1 + .../UI/View/ModalModifier/ModalView.swift | 21 +++++ .../Search/Sources/UI/View/ExploreView.swift | 85 ++++++++++--------- .../Sources/ViewModel/ExploreViewModel.swift | 2 +- 4 files changed, 68 insertions(+), 41 deletions(-) diff --git a/PingPong/Projects/Feature/Home/Project.swift b/PingPong/Projects/Feature/Home/Project.swift index 7dc8f37c..72d85731 100644 --- a/PingPong/Projects/Feature/Home/Project.swift +++ b/PingPong/Projects/Feature/Home/Project.swift @@ -23,6 +23,7 @@ let project = Project.makeAppModule( .core(implements: .Authorization), .core(implements: .Common), .feature(implements: .Bake), + .feature(implements: .Search), .SPM.PopupView, .SPM.Inject, diff --git a/PingPong/Projects/Feature/Home/Sources/UI/View/ModalModifier/ModalView.swift b/PingPong/Projects/Feature/Home/Sources/UI/View/ModalModifier/ModalView.swift index 959072f9..dbede8b8 100644 --- a/PingPong/Projects/Feature/Home/Sources/UI/View/ModalModifier/ModalView.swift +++ b/PingPong/Projects/Feature/Home/Sources/UI/View/ModalModifier/ModalView.swift @@ -11,6 +11,7 @@ import DesignSystem import Foundation import Model import SwiftUI +import Search public struct ModalView: View { let config: SheetManager.Config @@ -18,6 +19,8 @@ public struct ModalView: View { let defaultYoffset: CGFloat @StateObject private var viewModel: CommonViewViewModel + @StateObject var exploreViewViewModel: ExploreViewModel = ExploreViewModel() + let didClose: () -> Void @@ -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() } } diff --git a/PingPong/Projects/Feature/Search/Sources/UI/View/ExploreView.swift b/PingPong/Projects/Feature/Search/Sources/UI/View/ExploreView.swift index 51200ca7..587e5d8d 100644 --- a/PingPong/Projects/Feature/Search/Sources/UI/View/ExploreView.swift +++ b/PingPong/Projects/Feature/Search/Sources/UI/View/ExploreView.swift @@ -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 { @@ -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{ diff --git a/PingPong/Projects/Feature/Search/Sources/ViewModel/ExploreViewModel.swift b/PingPong/Projects/Feature/Search/Sources/ViewModel/ExploreViewModel.swift index d3853769..6d274d09 100644 --- a/PingPong/Projects/Feature/Search/Sources/ViewModel/ExploreViewModel.swift +++ b/PingPong/Projects/Feature/Search/Sources/ViewModel/ExploreViewModel.swift @@ -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),