Skip to content

Commit 82c8015

Browse files
authored
Merge pull request #324 from weiran/claude/feed-category-loading-state-011CUhjzTbEhavoXDwAGfgv1
Show loading state when switching category
2 parents edb5b75 + 478cd20 commit 82c8015

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Features/Feed/Sources/Feed/FeedView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public struct FeedView<NavigationStore: NavigationStoreProtocol>: View {
9292
searchText = newValue
9393
}
9494
}
95+
.onChange(of: selectedPostType) { _ in
96+
// Clear selection when category changes to prevent stale sidebar selection
97+
selectedPostId = nil
98+
}
9599
.task { @Sendable in
96100
// Set the navigation store for the voting view model
97101
votingViewModel.navigationStore = navigationStore
@@ -121,7 +125,7 @@ public struct FeedView<NavigationStore: NavigationStoreProtocol>: View {
121125
Group {
122126
if viewModel.hasActiveSearch {
123127
searchContentView
124-
} else if viewModel.isLoading, viewModel.posts.isEmpty {
128+
} else if viewModel.isLoading && viewModel.posts.isEmpty && viewModel.postType != .bookmarks {
125129
AppLoadingStateView(message: "Loading...")
126130
} else if shouldShowBookmarksEmptyState {
127131
AppEmptyStateView(
@@ -172,6 +176,7 @@ public struct FeedView<NavigationStore: NavigationStoreProtocol>: View {
172176
.if(isSidebar) { view in view.listStyle(.sidebar) }
173177
.if(!isSidebar) { view in view.listStyle(.plain) }
174178
.frame(maxWidth: .infinity, maxHeight: .infinity)
179+
.id(selectedPostType)
175180
}
176181

177182
@ViewBuilder

Features/Feed/Sources/Feed/FeedViewModel.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,15 @@ public final class FeedViewModel: @unchecked Sendable {
213213

214214
postType = newType
215215
persistLastFeedCategoryIfNeeded()
216-
await refreshFeed()
216+
reset(clearPosts: true) // Clear posts immediately to prevent flash of old data
217+
await feedLoader.refresh()
217218
}
218219

219220
@MainActor
220-
private func reset() {
221+
private func reset(clearPosts: Bool = false) {
222+
if clearPosts {
223+
feedLoader.data = []
224+
}
221225
postIds = Set()
222226
pageIndex = 1
223227
lastPostId = 0

0 commit comments

Comments
 (0)