2021-06-27 04:59:55 +05:30
|
|
|
import Defaults
|
2021-06-24 03:49:58 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideosListView: View {
|
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
|
2021-06-28 20:32:13 +05:30
|
|
|
VideoListRowView(video: video)
|
2021-06-24 03:49:58 +05:30
|
|
|
.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") {
|
2021-06-28 20:32:13 +05:30
|
|
|
Defaults[.openChannel] = Channel.from(video: video)
|
2021-06-24 03:49:58 +05:30
|
|
|
tabSelection = .channel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func closeChannelButton(name: String) -> some View {
|
|
|
|
Button("Close \(name) Channel") {
|
2021-06-28 20:32:13 +05:30
|
|
|
Defaults.reset(.openChannel)
|
2021-06-24 03:49:58 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var listRowInsets: EdgeInsets {
|
|
|
|
EdgeInsets(top: .zero, leading: .zero, bottom: .zero, trailing: 30)
|
|
|
|
}
|
|
|
|
}
|