From 27601f5009f65845d3ef9559dcaf4f4fa87c3eb5 Mon Sep 17 00:00:00 2001 From: cirtuare Date: Fri, 17 Jan 2025 18:43:41 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20SearchSuggestion=20=EB=B0=94=EC=9D=B8?= =?UTF-8?q?=EB=94=A9=20=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EC=A7=81=20(#39)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Upload/View/SpotSearchView.swift | 14 +++++++++++ .../View/SpotSearchViewController.swift | 24 ++++++++++++------- .../ViewModel/SpotSearchViewModel.swift | 10 ++++++++ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ACON-iOS/ACON-iOS/Presentation/Upload/View/SpotSearchView.swift b/ACON-iOS/ACON-iOS/Presentation/Upload/View/SpotSearchView.swift index c66fd14..620715e 100644 --- a/ACON-iOS/ACON-iOS/Presentation/Upload/View/SpotSearchView.swift +++ b/ACON-iOS/ACON-iOS/Presentation/Upload/View/SpotSearchView.swift @@ -273,3 +273,17 @@ extension SpotSearchView { } } + + +// MARK: - Make RecommendedSpotButton + +extension SpotSearchView { + + func bindData(_ data: SearchSuggestionModel) { + for i in 0...4 { + let button = makeRecommendedSpotButton(data.spotList[i]) + searchSuggestionStackView.addArrangedSubview(button) + } + } + +} diff --git a/ACON-iOS/ACON-iOS/Presentation/Upload/View/SpotSearchViewController.swift b/ACON-iOS/ACON-iOS/Presentation/Upload/View/SpotSearchViewController.swift index e954dc1..1045ee0 100644 --- a/ACON-iOS/ACON-iOS/Presentation/Upload/View/SpotSearchViewController.swift +++ b/ACON-iOS/ACON-iOS/Presentation/Upload/View/SpotSearchViewController.swift @@ -37,10 +37,15 @@ class SpotSearchViewController: BaseViewController { addTarget() registerCell() setDelegate() + bindViewModel() } var dismissCompletion: (() -> Void)? - + + override func viewWillAppear(_ animated: Bool) { + // TODO: - getSearchSuggestion 서버통신 + } + override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) @@ -68,7 +73,6 @@ class SpotSearchViewController: BaseViewController { self.view.backgroundColor = .glaW10 self.view.backgroundColor?.withAlphaComponent(0.95) - setRecommendedSpotStackView(data: spotSearchViewModel.searchSuggestionDummyData) } func addTarget() { @@ -120,17 +124,19 @@ private extension SpotSearchViewController { } -// MARK: - Set UI +// MARK: - Bind ViewModel private extension SpotSearchViewController { - - func setRecommendedSpotStackView(data: SearchSuggestionModel) { - for i in 0...4 { - let button = spotSearchView.makeRecommendedSpotButton(data.spotList[i]) - spotSearchView.searchSuggestionStackView.addArrangedSubview(button) + + func bindViewModel() { + self.spotSearchViewModel.onSuccessGetSearchSuggestion.bind { [weak self] onSuccess in + guard let onSuccess, let data = self?.spotSearchViewModel.searchSuggestionData.value else { return } + if onSuccess { + self?.spotSearchView.bindData(data) + } } } - + } diff --git a/ACON-iOS/ACON-iOS/Presentation/Upload/ViewModel/SpotSearchViewModel.swift b/ACON-iOS/ACON-iOS/Presentation/Upload/ViewModel/SpotSearchViewModel.swift index 3bc19a0..25326b4 100644 --- a/ACON-iOS/ACON-iOS/Presentation/Upload/ViewModel/SpotSearchViewModel.swift +++ b/ACON-iOS/ACON-iOS/Presentation/Upload/ViewModel/SpotSearchViewModel.swift @@ -9,6 +9,11 @@ import Foundation class SpotSearchViewModel { + // TODO: - 추후 기본값 nil로 변경 + let onSuccessGetSearchSuggestion: ObservablePattern = ObservablePattern(nil) + + var searchSuggestionData: ObservablePattern = ObservablePattern(nil) + // TODO: - search keyword 엠티뷰와 분기처리 (data.count == 0 ? ) let searchKeywordDummyData: [SearchKeywordModel] = [ @@ -26,4 +31,9 @@ class SpotSearchViewModel { let searchSuggestionDummyData: SearchSuggestionModel = SearchSuggestionModel(spotList: ["하이디라오", "신의주찹쌀순대", "뭐시기저시기", "카이센동우니도", "하잉"]) + init() { + self.searchSuggestionData.value = searchSuggestionDummyData + self.onSuccessGetSearchSuggestion.value = true + } + }