diff options
Diffstat (limited to 'Sora/Views/Post')
| -rw-r--r-- | Sora/Views/Post/Grid/PostGridView.swift | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift index 518b305..025c3d2 100644 --- a/Sora/Views/Post/Grid/PostGridView.swift +++ b/Sora/Views/Post/Grid/PostGridView.swift @@ -253,14 +253,19 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length await performLocalSearch() } } else { - currentLocalTask = Task(priority: .userInitiated) { - await fetchLocalPosts( - page: 1, - tags: localSearchText.components(separatedBy: .whitespaces).filter { component in - !component.isEmpty - }, - replace: true - ) + let currentTags = localSearchText.components(separatedBy: .whitespaces).filter { !$0.isEmpty } + let hasPosts = !localPosts.isEmpty + let initialTags = initialTag.components(separatedBy: .whitespaces).filter { !$0.isEmpty } + let needsFetch = !hasPosts || currentTags != initialTags + + if needsFetch { + currentLocalTask = Task(priority: .userInitiated) { + await fetchLocalPosts( + page: 1, + tags: currentTags, + replace: true + ) + } } } } |