import Foundation // MARK: - HomeViewModel // Fetches home-screen data: continue reading, recently updated, stats, subscription feed. // Uses @Observable (iOS 17+). @Observable @MainActor final class HomeViewModel { var continueReading: [ContinueReadingItem] = [] var recentlyUpdated: [Book] = [] var stats: HomeStats? var subscriptionFeed: [SubscriptionFeedItem] = [] var isLoading = false var error: String? func load() async { isLoading = true error = nil do { let data = try await APIClient.shared.homeData() continueReading = data.continueReading.map { ContinueReadingItem(book: $0.book, chapter: $0.chapter) } recentlyUpdated = data.recentlyUpdated stats = data.stats subscriptionFeed = data.subscriptionFeed } catch { if !(error is CancellationError) { self.error = error.localizedDescription } } isLoading = false } }