From 612056eed7aeb57143f6e4973d261eda556919e2 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 11 Sep 2025 23:18:20 -0700 Subject: feat: Development commit --- Sora/Views/Post/Grid/PostGridView.swift | 26 +++++++++++++++++++++----- 1 file 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 -- cgit v1.2.3