mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Settings for iOS/macOS
This commit is contained in:
@@ -4,7 +4,7 @@ struct TrendingCountry: View {
|
||||
static let prompt = "Country Name or Code"
|
||||
@Binding var selectedCountry: Country?
|
||||
|
||||
@ObservedObject private var store = Store(Country.allCases)
|
||||
@StateObject private var store = Store(Country.allCases)
|
||||
|
||||
@State private var query: String = ""
|
||||
@State private var selection: Country?
|
||||
|
@@ -2,18 +2,85 @@ import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct TrendingView: View {
|
||||
@StateObject private var store = Store<[Video]>()
|
||||
|
||||
@State private var category: TrendingCategory = .default
|
||||
@State private var country: Country! = .pl
|
||||
@State private var selectingCountry = false
|
||||
@State private var presentingCountrySelection = false
|
||||
|
||||
@ObservedObject private var store = Store<[Video]>()
|
||||
@EnvironmentObject<InvidiousAPI> private var api
|
||||
|
||||
var resource: Resource {
|
||||
InvidiousAPI.shared.trending(category: category, country: country)
|
||||
let resource = api.trending(category: category, country: country)
|
||||
resource.addObserver(store)
|
||||
|
||||
return resource
|
||||
}
|
||||
|
||||
init() {
|
||||
resource.addObserver(store)
|
||||
var body: some View {
|
||||
Section {
|
||||
VStack(alignment: .center, spacing: 2) {
|
||||
#if os(tvOS)
|
||||
toolbar
|
||||
.scaleEffect(0.85)
|
||||
#endif
|
||||
|
||||
if store.collection.isEmpty {
|
||||
Text("Loading")
|
||||
}
|
||||
|
||||
VideosView(videos: store.collection)
|
||||
}
|
||||
}
|
||||
#if os(tvOS)
|
||||
.fullScreenCover(isPresented: $presentingCountrySelection) {
|
||||
TrendingCountry(selectedCountry: $country)
|
||||
}
|
||||
#else
|
||||
.sheet(isPresented: $presentingCountrySelection) {
|
||||
TrendingCountry(selectedCountry: $country)
|
||||
#if os(macOS)
|
||||
.frame(minWidth: 400, minHeight: 400)
|
||||
#endif
|
||||
}
|
||||
.navigationTitle("Trending")
|
||||
#endif
|
||||
#if os(macOS)
|
||||
.toolbar {
|
||||
ToolbarItemGroup {
|
||||
categoryButton
|
||||
countryButton
|
||||
}
|
||||
}
|
||||
#elseif os(iOS)
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .bottomBar) {
|
||||
Group {
|
||||
HStack {
|
||||
Text("Category")
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
categoryButton
|
||||
}
|
||||
|
||||
HStack {
|
||||
Text("Country")
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
countryButton
|
||||
}
|
||||
}
|
||||
.transaction { t in t.animation = .none }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
.onChange(of: resource) { resource in
|
||||
resource.load()
|
||||
}
|
||||
.onAppear {
|
||||
resource.addObserver(store)
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
var toolbar: some View {
|
||||
@@ -38,67 +105,21 @@ struct TrendingView: View {
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Section {
|
||||
VStack(alignment: .center, spacing: 2) {
|
||||
#if os(tvOS)
|
||||
toolbar
|
||||
.scaleEffect(0.85)
|
||||
#endif
|
||||
|
||||
VideosView(videos: store.collection)
|
||||
|
||||
#if os(iOS)
|
||||
toolbar
|
||||
.font(.system(size: 14))
|
||||
.padding(.horizontal)
|
||||
.padding(.vertical, 10)
|
||||
.overlay(Divider().offset(x: 0, y: -2), alignment: .topTrailing)
|
||||
.transaction { t in t.animation = .none }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if os(tvOS)
|
||||
.fullScreenCover(isPresented: $selectingCountry, onDismiss: { setCountry(country) }) {
|
||||
TrendingCountry(selectedCountry: $country)
|
||||
}
|
||||
#else
|
||||
.sheet(isPresented: $selectingCountry, onDismiss: { setCountry(country) }) {
|
||||
TrendingCountry(selectedCountry: $country)
|
||||
#if os(macOS)
|
||||
.frame(minWidth: 400, minHeight: 400)
|
||||
#endif
|
||||
}
|
||||
.navigationTitle("Trending")
|
||||
#endif
|
||||
#if os(macOS)
|
||||
.toolbar {
|
||||
ToolbarItemGroup {
|
||||
categoryButton
|
||||
countryButton
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
.onAppear {
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
var categoryButton: some View {
|
||||
#if os(tvOS)
|
||||
Button(category.name) {
|
||||
setCategory(category.next())
|
||||
self.category = category.next()
|
||||
}
|
||||
.contextMenu {
|
||||
ForEach(TrendingCategory.allCases) { category in
|
||||
Button(category.name) { setCategory(category) }
|
||||
Button(category.name) { self.category = category }
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
Menu(category.name) {
|
||||
ForEach(TrendingCategory.allCases) { category in
|
||||
Button(action: { setCategory(category) }) {
|
||||
Button(action: { self.category = category }) {
|
||||
if category == self.category {
|
||||
Label(category.name, systemImage: "checkmark")
|
||||
} else {
|
||||
@@ -112,30 +133,17 @@ struct TrendingView: View {
|
||||
|
||||
var countryButton: some View {
|
||||
Button(action: {
|
||||
selectingCountry.toggle()
|
||||
presentingCountrySelection.toggle()
|
||||
resource.removeObservers(ownedBy: store)
|
||||
}) {
|
||||
Text("\(country.flag) \(country.id)")
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func setCategory(_ category: TrendingCategory) {
|
||||
resource.removeObservers(ownedBy: store)
|
||||
self.category = category
|
||||
resource.addObserver(store)
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
|
||||
fileprivate func setCountry(_ country: Country) {
|
||||
self.country = country
|
||||
resource.addObserver(store)
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
struct TrendingView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
TrendingView()
|
||||
.environmentObject(NavigationState())
|
||||
.environmentObject(NavigationModel())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user