diff --git a/JUDA_iOS/JUDA/View/Posts/PostsView.swift b/JUDA_iOS/JUDA/View/Posts/PostsView.swift index ad0cfec..0785bcd 100644 --- a/JUDA_iOS/JUDA/View/Posts/PostsView.swift +++ b/JUDA_iOS/JUDA/View/Posts/PostsView.swift @@ -26,15 +26,14 @@ struct PostsView: View { // 상단 서치바 SearchBar(inputText: $postSearchText, isFocused: $isFocused) { Task(priority: .high) { + postViewModel.clearSearchedPosts() await postViewModel.getSearchedPosts(from: postSearchText) } } // 서치바 Text가 없을 때, 게시글 검색 결과 비워주기 .onChange(of: postSearchText) { _ in if postSearchText == "" { - postViewModel.searchPostsByUserName = [] - postViewModel.searchPostsByDrinkTag = [] - postViewModel.searchPostsByFoodTag = [] + postViewModel.clearSearchedPosts() } } // MARK: 검색어 입력 중 diff --git a/JUDA_iOS/JUDA/ViewModel/Posts/PostViewModel.swift b/JUDA_iOS/JUDA/ViewModel/Posts/PostViewModel.swift index 7c61a7c..db9987e 100644 --- a/JUDA_iOS/JUDA/ViewModel/Posts/PostViewModel.swift +++ b/JUDA_iOS/JUDA/ViewModel/Posts/PostViewModel.swift @@ -293,6 +293,13 @@ extension PostViewModel { searchPostsByFoodTag = result } } + + // '검색된 게시글' 배열 요소 전체 삭제 + func clearSearchedPosts() { + searchPostsByUserName = [] + searchPostsByDrinkTag = [] + searchPostsByFoodTag = [] + } } // MARK: - Report Upload