Feed resilience, clearer empty states, and read/unread

- Don't blank the feed on refresh: keep current stories until new data
  arrives, and ignore benign URLError.cancelled (-999) so a network blip
  no longer wipes the list. Coalesce WebSocket story.created bursts into a
  single debounced refresh.
- Empty state now distinguishes polling, couldn't-reach-server (with the
  error + host + Retry), offline, and genuinely-empty.
- Track read stories in SwiftData (ReadStory); mark a story read when opened
  and drop/dim its signal stripe across the feed and Latest/Saved/Search.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Robin Kutesa
2026-06-18 23:22:56 +03:00
parent 4e4d109380
commit 1e582f5120
9 changed files with 137 additions and 23 deletions

View File

@@ -30,6 +30,7 @@ struct StoryDetailView: View {
let story: StorySummary
@Environment(\.dismiss) private var dismiss
@Environment(\.modelContext) private var modelContext
@StateObject private var vm = StoryDetailViewModel()
@Query private var cachedArticles: [CachedArticle]
@@ -102,7 +103,23 @@ struct StoryDetailView: View {
.toolbarBackground(Color.black, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
.preferredColorScheme(.dark)
.task { await vm.load(id: story.id) }
.task {
markRead()
await vm.load(id: story.id)
}
}
// MARK: - Read state
private func markRead() {
let id = story.id
let existing = try? modelContext.fetch(
FetchDescriptor<ReadStory>(predicate: #Predicate { $0.id == id })
)
if existing?.first == nil {
modelContext.insert(ReadStory(id: id))
try? modelContext.save()
}
}
// MARK: - Pieces