From 8e33a6d206af08e75d3d5ecc4db69fae978b2545 Mon Sep 17 00:00:00 2001 From: SweetPumpkinCK <80156515+bdrsky2010@users.noreply.github.com> Date: Fri, 12 Apr 2024 22:19:46 +0900 Subject: [PATCH] =?UTF-8?q?[Modify]=20PostSearch=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B2=AB=EB=B2=88=EC=A7=B8=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=20#173?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JUDA_iOS/JUDA/View/Posts/PostsView.swift | 5 ++--- JUDA_iOS/JUDA/ViewModel/Posts/PostViewModel.swift | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) 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