1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Home/FavoriteResourceObserver.swift

23 lines
1018 B
Swift
Raw Normal View History

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