yattee/Apple TV/TrendingView.swift

65 lines
1.6 KiB
Swift
Raw Normal View History

2021-06-17 10:02:39 +00:00
import SwiftUI
struct TrendingView: View {
@EnvironmentObject private var state: AppState
@ObservedObject private var videosProvider = TrendingVideosProvider()
2021-06-26 09:39:35 +00:00
@SceneStorage("category") var category: TrendingCategory = .default
@SceneStorage("country") var country: Country = .pl
2021-06-17 10:02:39 +00:00
@State private var selectingCountry = false
var body: some View {
Section {
VStack(alignment: .leading, spacing: 2) {
HStack(alignment: .top) {
Spacer()
categoryButton
countryFlag
countryButton
2021-06-17 10:02:39 +00:00
Spacer()
}
.scaleEffect(0.85)
2021-06-26 23:29:55 +00:00
VideosView(videos: videos)
2021-06-17 10:02:39 +00:00
}
}
}
var videos: [Video] {
2021-06-26 09:39:35 +00:00
videosProvider.load(category: category, country: country)
2021-06-17 10:02:39 +00:00
return videosProvider.videos
}
var categoryButton: some View {
2021-06-26 09:39:35 +00:00
Button(category.name) {
category = category.next()
}
.contextMenu {
ForEach(TrendingCategory.allCases) { category in
Button(category.name) {
2021-06-26 09:39:35 +00:00
self.category = category
}
}
}
}
var countryFlag: some View {
2021-06-26 09:39:35 +00:00
Text(country.flag)
.font(.system(size: 60))
}
var countryButton: some View {
2021-06-26 09:39:35 +00:00
Button(country.rawValue) {
selectingCountry.toggle()
}
.fullScreenCover(isPresented: $selectingCountry) {
2021-06-26 09:39:35 +00:00
TrendingCountrySelectionView(selectedCountry: $country)
}
}
2021-06-17 10:02:39 +00:00
}