1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 22:30:32 +05:30
yattee/Shared/Views/ChannelPlaylistView.swift

101 lines
2.6 KiB
Swift
Raw Normal View History

2021-10-23 04:34:03 +05:30
import Siesta
import SwiftUI
struct ChannelPlaylistView: View {
var playlist: ChannelPlaylist
2021-10-27 04:29:59 +05:30
@State private var presentingShareSheet = false
2021-11-13 21:15:47 +05:30
@State private var shareURL: URL?
2021-10-27 04:29:59 +05:30
2021-10-23 04:34:03 +05:30
@StateObject private var store = Store<ChannelPlaylist>()
2021-11-11 03:35:59 +05:30
#if os(iOS)
@Environment(\.inNavigationView) private var inNavigationView
#endif
2021-10-23 04:34:03 +05:30
@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-02 03:26:18 +05:30
HStack {
Text(playlist.title)
.font(.title2)
.frame(alignment: .leading)
Spacer()
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title)))
.labelStyle(.iconOnly)
}
2021-10-23 04:34:03 +05:30
#endif
VerticalCells(items: items)
}
2021-10-27 04:29:59 +05:30
#if os(iOS)
2021-11-08 21:59:35 +05:30
.sheet(isPresented: $presentingShareSheet) {
2021-11-13 21:15:47 +05:30
if let shareURL = shareURL {
ShareSheet(activityItems: [shareURL])
2021-10-27 04:29:59 +05:30
}
2021-11-08 21:59:35 +05:30
}
2021-10-27 04:29:59 +05:30
#endif
2021-10-23 04:34:03 +05:30
.onAppear {
resource?.addObserver(store)
resource?.loadIfNeeded()
}
#if !os(tvOS)
2021-11-08 21:59:35 +05:30
.toolbar {
ToolbarItem(placement: .navigation) {
ShareButton(
contentItem: contentItem,
2021-11-13 21:15:47 +05:30
presentingShareSheet: $presentingShareSheet,
shareURL: $shareURL
2021-11-08 21:59:35 +05:30
)
}
2021-10-27 04:29:59 +05:30
2021-11-08 21:59:35 +05:30
ToolbarItem {
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title)))
2021-10-23 04:34:03 +05:30
}
2021-11-08 21:59:35 +05:30
}
.navigationTitle(playlist.title)
2021-10-23 04:34:03 +05:30
#else
2021-11-08 21:59:35 +05:30
.background(.thickMaterial)
2021-10-23 04:34:03 +05:30
#endif
}
2021-10-27 04:29:59 +05:30
private var contentItem: ContentItem {
ContentItem(playlist: playlist)
}
2021-10-23 04:34:03 +05:30
}
struct ChannelPlaylistView_Previews: PreviewProvider {
static var previews: some View {
ChannelPlaylistView(playlist: ChannelPlaylist.fixture)
.injectFixtureEnvironmentObjects()
}
}