yattee/Shared/Favorites/FavoriteResourceObserver.swift

23 lines
1018 B
Swift
Raw Normal View History

2021-11-05 22:44:52 +00:00
import Foundation
import Siesta
final class FavoriteResourceObserver: ObservableObject, ResourceObserver {
2021-11-09 17:43:15 +00:00
@Published var contentItems = [ContentItem]()
2021-11-05 22:44:52 +00:00
func resourceChanged(_ resource: Resource, event _: ResourceEvent) {
if let videos: [Video] = resource.typedContent() {
2021-11-09 17:43:15 +00:00
contentItems = videos.map { ContentItem(video: $0) }
2021-11-05 22:44:52 +00:00
} else if let channel: Channel = resource.typedContent() {
2021-11-09 17:43:15 +00:00
contentItems = channel.videos.map { ContentItem(video: $0) }
2021-11-05 22:44:52 +00:00
} else if let playlist: ChannelPlaylist = resource.typedContent() {
2021-11-09 17:43:15 +00:00
contentItems = playlist.videos.map { ContentItem(video: $0) }
2021-11-05 22:44:52 +00:00
} else if let playlist: Playlist = resource.typedContent() {
2021-11-09 17:43:15 +00:00
contentItems = playlist.videos.map { ContentItem(video: $0) }
2022-01-10 19:06:43 +00:00
} else if let page: SearchPage = resource.typedContent() {
contentItems = page.results
2021-11-09 17:43:15 +00:00
} else if let items: [ContentItem] = resource.typedContent() {
contentItems = items
2021-11-05 22:44:52 +00:00
}
}
}