summaryrefslogtreecommitdiff
path: root/Sora/Views/Post
diff options
context:
space:
mode:
Diffstat (limited to 'Sora/Views/Post')
-rw-r--r--Sora/Views/Post/Grid/PostGridView.swift21
1 files changed, 21 insertions, 0 deletions
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift
index 5d08d2c..80130a4 100644
--- a/Sora/Views/Post/Grid/PostGridView.swift
+++ b/Sora/Views/Post/Grid/PostGridView.swift
@@ -77,6 +77,27 @@ struct PostGridView: View {
updateViewState(for: queryID, currentPage: newPage)
}
}
+ .onChange(of: manager.historyIndex) { _, newIndex in
+ guard newIndex >= 0 && newIndex < manager.searchHistory.count else { return }
+
+ let queryID = manager.searchHistory[newIndex].id
+
+ if let state = viewStates[queryID] {
+ manager.posts = state.posts
+ manager.currentPage = state.currentPage
+ } else {
+ manager.posts = []
+ manager.currentPage = 1
+
+ Task {
+ await manager.fetchPosts(
+ page: 1,
+ tags: manager.searchHistory[newIndex].tags,
+ replace: true
+ )
+ }
+ }
+ }
.toolbar {
#if os(macOS)
ToolbarItem {