2021-09-25 08:18:22 +00:00
|
|
|
import Siesta
|
2021-06-11 22:49:42 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct SubscriptionsView: View {
|
2021-09-25 08:18:22 +00:00
|
|
|
@StateObject private var store = Store<[Video]>()
|
2021-06-26 11:37:24 +00:00
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
@EnvironmentObject<InvidiousAPI> private var api
|
2021-06-11 22:49:42 +00:00
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
var feed: Resource {
|
|
|
|
api.feed
|
2021-06-28 10:43:07 +00:00
|
|
|
}
|
2021-06-26 11:37:24 +00:00
|
|
|
|
2021-06-28 10:43:07 +00:00
|
|
|
var body: some View {
|
2021-09-25 08:18:22 +00:00
|
|
|
SignInRequiredView(title: "Subscriptions") {
|
2021-09-26 22:28:42 +00:00
|
|
|
VideosCellsVertical(videos: store.collection)
|
2021-09-25 08:18:22 +00:00
|
|
|
.onAppear {
|
|
|
|
loadResources()
|
2021-09-19 17:31:21 +00:00
|
|
|
}
|
2021-09-25 08:18:22 +00:00
|
|
|
.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)
|
2021-06-28 10:43:07 +00:00
|
|
|
}
|
2021-09-25 08:18:22 +00:00
|
|
|
} else {
|
|
|
|
loadFeed(force: force)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate func loadFeed(force: Bool = false) {
|
|
|
|
_ = force ? feed.load() : feed.loadIfNeeded()
|
2021-06-11 22:49:42 +00:00
|
|
|
}
|
|
|
|
}
|