1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 22:30:32 +05:30
yattee/Apple TV/VideosListView.swift

48 lines
1.3 KiB
Swift
Raw Normal View History

2021-06-27 04:59:55 +05:30
import Defaults
2021-06-24 03:49:58 +05:30
import SwiftUI
struct VideosListView: View {
@EnvironmentObject private var state: AppState
2021-06-27 04:59:55 +05:30
@Default(.tabSelection) var tabSelection
2021-06-24 03:49:58 +05:30
var videos: [Video]
var body: some View {
Section {
List {
ForEach(videos) { video in
VideoListRow(video: video)
.contextMenu {
if tabSelection == .channel {
closeChannelButton(name: video.author)
} else {
openChannelButton(from: video)
}
}
.listRowInsets(listRowInsets)
}
}
.listStyle(GroupedListStyle())
}
}
func openChannelButton(from video: Video) -> some View {
Button("\(video.author) Channel") {
state.openChannel(from: video)
tabSelection = .channel
}
}
func closeChannelButton(name: String) -> some View {
Button("Close \(name) Channel") {
tabSelection = .popular
state.closeChannel()
}
}
var listRowInsets: EdgeInsets {
EdgeInsets(top: .zero, leading: .zero, bottom: .zero, trailing: 30)
}
}