2021-10-22 23:04:03 +00:00
|
|
|
import Siesta
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChannelPlaylistView: View {
|
|
|
|
var playlist: ChannelPlaylist
|
|
|
|
|
2021-10-26 22:59:59 +00:00
|
|
|
@State private var presentingShareSheet = false
|
|
|
|
|
2021-10-22 23:04:03 +00:00
|
|
|
@StateObject private var store = Store<ChannelPlaylist>()
|
|
|
|
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
@Environment(\.inNavigationView) private var inNavigationView
|
|
|
|
|
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
|
|
|
|
|
|
|
var items: [ContentItem] {
|
|
|
|
ContentItem.array(of: store.item?.videos ?? [])
|
|
|
|
}
|
|
|
|
|
|
|
|
var resource: Resource? {
|
|
|
|
accounts.api.channelPlaylist(playlist.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
#if os(iOS)
|
|
|
|
if inNavigationView {
|
|
|
|
content
|
|
|
|
} else {
|
|
|
|
PlayerControlsView {
|
|
|
|
content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
PlayerControlsView {
|
|
|
|
content
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
var content: some View {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
#if os(tvOS)
|
2021-11-01 21:56:18 +00:00
|
|
|
HStack {
|
|
|
|
Text(playlist.title)
|
|
|
|
.font(.title2)
|
|
|
|
.frame(alignment: .leading)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title)))
|
|
|
|
.labelStyle(.iconOnly)
|
|
|
|
}
|
2021-10-22 23:04:03 +00:00
|
|
|
#endif
|
|
|
|
VerticalCells(items: items)
|
|
|
|
}
|
2021-10-26 22:59:59 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.sheet(isPresented: $presentingShareSheet) {
|
2021-10-28 17:14:55 +00:00
|
|
|
if let url = accounts.api.shareURL(contentItem) {
|
|
|
|
ShareSheet(activityItems: [url])
|
|
|
|
}
|
2021-10-26 22:59:59 +00:00
|
|
|
}
|
|
|
|
#endif
|
2021-10-22 23:04:03 +00:00
|
|
|
.onAppear {
|
|
|
|
resource?.addObserver(store)
|
|
|
|
resource?.loadIfNeeded()
|
|
|
|
}
|
|
|
|
#if !os(tvOS)
|
|
|
|
.toolbar {
|
2021-11-02 19:40:49 +00:00
|
|
|
ToolbarItem(placement: .navigation) {
|
2021-10-26 22:59:59 +00:00
|
|
|
ShareButton(
|
|
|
|
contentItem: contentItem,
|
|
|
|
presentingShareSheet: $presentingShareSheet
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-11-01 21:56:18 +00:00
|
|
|
ToolbarItem {
|
|
|
|
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title)))
|
2021-10-22 23:04:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationTitle(playlist.title)
|
|
|
|
|
|
|
|
#else
|
|
|
|
.background(.thickMaterial)
|
|
|
|
#endif
|
|
|
|
}
|
2021-10-26 22:59:59 +00:00
|
|
|
|
|
|
|
private var contentItem: ContentItem {
|
|
|
|
ContentItem(playlist: playlist)
|
|
|
|
}
|
2021-10-22 23:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ChannelPlaylistView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
ChannelPlaylistView(playlist: ChannelPlaylist.fixture)
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|