diff options
| author | Fuwn <[email protected]> | 2025-09-11 23:18:20 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-09-11 23:18:20 -0700 |
| commit | 612056eed7aeb57143f6e4973d261eda556919e2 (patch) | |
| tree | a89ce83efed5c7283a5263fbd854ed26088a0345 | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-612056eed7aeb57143f6e4973d261eda556919e2.tar.xz sora-testing-612056eed7aeb57143f6e4973d261eda556919e2.zip | |
feat: Development commit
| -rw-r--r-- | Sora/Views/Post/Grid/PostGridView.swift | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift index a5ff85a..3c7ebe3 100644 --- a/Sora/Views/Post/Grid/PostGridView.swift +++ b/Sora/Views/Post/Grid/PostGridView.swift @@ -268,6 +268,8 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length let needsFetch = !hasPosts || currentTags != initialTags if needsFetch { + currentLocalTask?.cancel() + currentLocalTask = Task(priority: .userInitiated) { await fetchLocalPosts( page: 1, @@ -290,6 +292,8 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length ToolbarItem { Button(action: { if initialTag != nil { + currentLocalTask?.cancel() + currentLocalTask = Task(priority: .userInitiated) { await fetchLocalPosts( page: 1, @@ -418,6 +422,8 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length .navigationTitle(initialTag != nil ? initialTag! : "Posts") .refreshable { if initialTag != nil { + currentLocalTask?.cancel() + currentLocalTask = Task(priority: .userInitiated) { await fetchLocalPosts( page: 1, @@ -522,7 +528,13 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length ) settings.appendToSearchHistory(query) - await fetchLocalPosts(page: 1, tags: inputTags, replace: true) + currentLocalTask?.cancel() + + currentLocalTask = Task(priority: .userInitiated) { + await fetchLocalPosts(page: 1, tags: inputTags, replace: true) + } + + await currentLocalTask?.value } private func loadLocalNextPage() async { @@ -534,7 +546,13 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length !component.isEmpty } - await fetchLocalPosts(page: localCurrentPage, tags: inputTags, replace: false) + currentLocalTask?.cancel() + + currentLocalTask = Task(priority: .userInitiated) { + await fetchLocalPosts(page: localCurrentPage, tags: inputTags, replace: false) + } + + await currentLocalTask?.value } private func fetchLocalPosts( @@ -542,13 +560,11 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length ) async { guard !localIsLoading else { return } - currentLocalTask?.cancel() - localIsLoading = true + localError = nil defer { localIsLoading = false - currentLocalTask = nil } let flavor = manager.flavor |