mirror of
https://github.com/yattee/yattee.git
synced 2025-10-12 02:18:17 +00:00
Settings for iOS/macOS
This commit is contained in:
@@ -1,30 +1,46 @@
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct SubscriptionsView: View {
|
||||
@ObservedObject private var store = Store<[Video]>()
|
||||
@StateObject private var store = Store<[Video]>()
|
||||
|
||||
var resource = InvidiousAPI.shared.feed
|
||||
@EnvironmentObject<InvidiousAPI> private var api
|
||||
|
||||
init() {
|
||||
resource.addObserver(store)
|
||||
var feed: Resource {
|
||||
api.feed
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VideosView(videos: store.collection)
|
||||
.onAppear {
|
||||
if let home = InvidiousAPI.shared.home.loadIfNeeded() {
|
||||
home.onSuccess { _ in
|
||||
resource.loadIfNeeded()
|
||||
}
|
||||
} else {
|
||||
resource.loadIfNeeded()
|
||||
SignInRequiredView(title: "Subscriptions") {
|
||||
VideosView(videos: store.collection)
|
||||
.onAppear {
|
||||
loadResources()
|
||||
}
|
||||
.onChange(of: api.account) { _ in
|
||||
loadResources(force: true)
|
||||
}
|
||||
.onChange(of: feed) { _ in
|
||||
loadResources(force: true)
|
||||
}
|
||||
}
|
||||
.refreshable {
|
||||
loadResources(force: true)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func loadResources(force: Bool = false) {
|
||||
feed.addObserver(store)
|
||||
|
||||
if let request = force ? api.home.load() : api.home.loadIfNeeded() {
|
||||
request.onSuccess { _ in
|
||||
loadFeed(force: force)
|
||||
}
|
||||
.refreshable {
|
||||
resource.load()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("Subscriptions")
|
||||
#endif
|
||||
} else {
|
||||
loadFeed(force: force)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func loadFeed(force: Bool = false) {
|
||||
_ = force ? feed.load() : feed.loadIfNeeded()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user