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