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) }
|
|
|
|
} else if let items: [ContentItem] = resource.typedContent() {
|
|
|
|
contentItems = items
|
2021-11-05 22:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|