diff options
| author | Fuwn <[email protected]> | 2025-03-18 04:44:08 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-03-18 04:44:08 -0700 |
| commit | 82b9b4aa5a9e547acd8b7c64c25d5770150d5392 (patch) | |
| tree | 5039946d5de0362ce497b698e1290b32c75308cc | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-82b9b4aa5a9e547acd8b7c64c25d5770150d5392.tar.xz sora-testing-82b9b4aa5a9e547acd8b7c64c25d5770150d5392.zip | |
feat: Development commit
| -rw-r--r-- | Sora/Data/Booru/BooruManager.swift | 17 | ||||
| -rw-r--r-- | Sora/Views/Post/Grid/PostGridView.swift | 6 |
2 files changed, 13 insertions, 10 deletions
diff --git a/Sora/Data/Booru/BooruManager.swift b/Sora/Data/Booru/BooruManager.swift index c77d182..2468a92 100644 --- a/Sora/Data/Booru/BooruManager.swift +++ b/Sora/Data/Booru/BooruManager.swift @@ -17,6 +17,7 @@ class BooruManager: ObservableObject { @Published var provider: BooruProvider @Published var historyIndex: Int = -1 @Published var searchHistory: [BooruSearchQuery] = [] + @Published var isNavigatingHistory = false // MARK: - Private Properties private var currentTask: Task<Void, Never>? @@ -102,7 +103,7 @@ class BooruManager: ObservableObject { pageCache.setObject(cacheEntry, forKey: cacheKey) updatePosts(newPosts, replace: replace) } catch { - if (error as? URLError)?.code != .cancelled { debugPrint("fetchPosts: \(error)") } + debugPrint("BooruManager.fetchPosts: \(error)") } } } @@ -158,22 +159,22 @@ class BooruManager: ObservableObject { func goBackInHistory() { guard canGoBackInHistory else { return } + isNavigatingHistory = true historyIndex -= 1 let previousQuery = searchHistory[historyIndex] searchText = previousQuery.tags.joined(separator: " ") - currentPage = previousQuery.page posts = [] - if tags.isEmpty { clearPageCache() } - currentTask?.cancel() currentTask = nil Task { - await fetchPosts(page: currentPage, tags: previousQuery.tags, replace: true) + await fetchPosts(tags: previousQuery.tags, replace: true) + + isNavigatingHistory = false } } @@ -181,11 +182,11 @@ class BooruManager: ObservableObject { guard canGoForwardInHistory else { return } historyIndex += 1 + isNavigatingHistory = true let nextQuery = searchHistory[historyIndex] searchText = nextQuery.tags.joined(separator: " ") - currentPage = nextQuery.page posts = [] clearPageCache() @@ -194,7 +195,9 @@ class BooruManager: ObservableObject { currentTask = nil Task { - await fetchPosts(page: currentPage, tags: nextQuery.tags, replace: true) + await fetchPosts(tags: nextQuery.tags, replace: true) + + isNavigatingHistory = false } } diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift index 8e5e1a7..3a1fcd3 100644 --- a/Sora/Views/Post/Grid/PostGridView.swift +++ b/Sora/Views/Post/Grid/PostGridView.swift @@ -45,7 +45,7 @@ struct PostGridView: View { PostDetailsView(post: post) } .onChange(of: manager.searchText) { _, _ in - if manager.searchText.isEmpty, !isSearching { + if manager.searchText.isEmpty, !isSearching, !manager.isNavigatingHistory { Task { manager.performSearch() } } } @@ -92,14 +92,14 @@ struct PostGridView: View { Button(action: { manager.goBackInHistory() }) { Label("Previous Search", systemImage: "chevron.left") } - .disabled(!(manager.historyIndex > 0)) + .disabled(!manager.canGoBackInHistory) } PlatformSpecificToolbarItem { Button(action: { manager.goForwardInHistory() }) { Label("Next Search", systemImage: "chevron.right") } - .disabled(!(manager.historyIndex < manager.searchHistory.count - 1)) + .disabled(!manager.canGoForwardInHistory) } } .navigationTitle("Posts") |