Skip to content

Commit

Permalink
[Feat] SearchSuggestion 바인딩 관련 로직 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
cirtuare committed Jan 17, 2025
1 parent 1d399ed commit 27601f5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
14 changes: 14 additions & 0 deletions ACON-iOS/ACON-iOS/Presentation/Upload/View/SpotSearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -68,7 +73,6 @@ class SpotSearchViewController: BaseViewController {

self.view.backgroundColor = .glaW10
self.view.backgroundColor?.withAlphaComponent(0.95)
setRecommendedSpotStackView(data: spotSearchViewModel.searchSuggestionDummyData)
}

func addTarget() {
Expand Down Expand Up @@ -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)
}
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import Foundation

class SpotSearchViewModel {

// TODO: - 추후 기본값 nil로 변경
let onSuccessGetSearchSuggestion: ObservablePattern<Bool> = ObservablePattern(nil)

var searchSuggestionData: ObservablePattern<SearchSuggestionModel> = ObservablePattern(nil)

// TODO: - search keyword 엠티뷰와 분기처리 (data.count == 0 ? )

let searchKeywordDummyData: [SearchKeywordModel] = [
Expand All @@ -26,4 +31,9 @@ class SpotSearchViewModel {

let searchSuggestionDummyData: SearchSuggestionModel = SearchSuggestionModel(spotList: ["하이디라오", "신의주찹쌀순대", "뭐시기저시기", "카이센동우니도", "하잉"])

init() {
self.searchSuggestionData.value = searchSuggestionDummyData
self.onSuccessGetSearchSuggestion.value = true
}

}

0 comments on commit 27601f5

Please sign in to comment.