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