mirror of
https://github.com/yattee/yattee.git
synced 2026-05-12 18:35:05 +00:00
Show cached channel header on tvOS while channel loads
Render subscriber count, Subscribe button, and (for subscribed channels) description in the tvOS loading state instead of just avatar + name + spinner. Seed the in-memory author cache when navigating to a channel from a video so the first-time channel view has a name and avatar to display immediately.
This commit is contained in:
@@ -14,6 +14,7 @@ struct CachedChannelData: Codable {
|
||||
let thumbnailURL: URL?
|
||||
let bannerURL: URL?
|
||||
let subscriberCount: Int?
|
||||
let description: String?
|
||||
|
||||
/// In-memory cache of author data from video detail API responses.
|
||||
@MainActor
|
||||
@@ -32,21 +33,25 @@ struct CachedChannelData: Codable {
|
||||
.appendingPathComponent("authors.json")
|
||||
}
|
||||
|
||||
init(name: String, thumbnailURL: URL?, bannerURL: URL?, subscriberCount: Int?) {
|
||||
init(name: String, thumbnailURL: URL?, bannerURL: URL?, subscriberCount: Int?, description: String? = nil) {
|
||||
self.name = name
|
||||
self.thumbnailURL = thumbnailURL
|
||||
self.bannerURL = bannerURL
|
||||
self.subscriberCount = subscriberCount
|
||||
self.description = description
|
||||
}
|
||||
|
||||
@MainActor
|
||||
static func cacheAuthor(_ author: Author) {
|
||||
guard author.thumbnailURL != nil || author.subscriberCount != nil else { return }
|
||||
guard !author.id.isEmpty, !author.name.isEmpty else { return }
|
||||
loadFromDiskIfNeeded()
|
||||
let existing = authorCache[author.id]
|
||||
authorCache[author.id] = CachedChannelData(
|
||||
name: author.name,
|
||||
thumbnailURL: author.thumbnailURL,
|
||||
bannerURL: nil,
|
||||
subscriberCount: author.subscriberCount
|
||||
thumbnailURL: author.thumbnailURL ?? existing?.thumbnailURL,
|
||||
bannerURL: existing?.bannerURL,
|
||||
subscriberCount: author.subscriberCount ?? existing?.subscriberCount,
|
||||
description: existing?.description
|
||||
)
|
||||
|
||||
// Evict oldest entries if over limit
|
||||
@@ -101,6 +106,7 @@ struct CachedChannelData: Codable {
|
||||
thumbnailURL = subscription.avatarURL
|
||||
bannerURL = subscription.bannerURL
|
||||
subscriberCount = subscription.subscriberCount
|
||||
description = subscription.channelDescription
|
||||
}
|
||||
|
||||
init(from recentChannel: RecentChannel) {
|
||||
@@ -108,6 +114,7 @@ struct CachedChannelData: Codable {
|
||||
thumbnailURL = recentChannel.thumbnailURLString.flatMap { URL(string: $0) }
|
||||
bannerURL = nil // RecentChannel doesn't store banner
|
||||
subscriberCount = recentChannel.subscriberCount
|
||||
description = nil
|
||||
}
|
||||
|
||||
/// Load cached data for a channel ID from Subscription or RecentChannel.
|
||||
|
||||
Reference in New Issue
Block a user