yattee/Apple TV/VideosView.swift

47 lines
1.3 KiB
Swift
Raw Normal View History

2021-06-11 21:40:35 +00:00
import SwiftUI
struct VideosView: View {
2021-06-17 10:02:39 +00:00
@EnvironmentObject private var state: AppState
2021-06-11 21:54:00 +00:00
2021-06-11 21:40:35 +00:00
@Binding var tabSelection: TabSelection
var videos: [Video]
var body: some View {
2021-06-11 22:49:42 +00:00
Section {
2021-06-11 21:40:35 +00:00
List {
ForEach(videos) { video in
VideoThumbnailView(video: video)
.contextMenu {
2021-06-11 21:54:00 +00:00
if tabSelection == .channel {
2021-06-11 21:40:35 +00:00
closeChannelButton(name: video.author)
} else {
openChannelButton(from: video)
}
}
.listRowInsets(listRowInsets)
}
}
.listStyle(GroupedListStyle())
}
}
2021-06-11 21:54:00 +00:00
2021-06-11 21:40:35 +00:00
func openChannelButton(from video: Video) -> some View {
2021-06-14 18:05:02 +00:00
Button("\(video.author) Channel") {
2021-06-11 21:40:35 +00:00
state.openChannel(from: video)
tabSelection = .channel
2021-06-14 18:05:02 +00:00
}
2021-06-11 21:40:35 +00:00
}
2021-06-11 21:54:00 +00:00
func closeChannelButton(name: String) -> some View {
2021-06-14 18:05:02 +00:00
Button("Close \(name) Channel") {
2021-06-11 21:54:00 +00:00
tabSelection = .popular
state.closeChannel()
2021-06-14 18:05:02 +00:00
}
2021-06-11 21:54:00 +00:00
}
2021-06-11 21:40:35 +00:00
var listRowInsets: EdgeInsets {
EdgeInsets(top: .zero, leading: .zero, bottom: .zero, trailing: 30)
}
}