1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 14:20:32 +05:30
yattee/Shared/Views/SubscriptionsView.swift

50 lines
1.2 KiB
Swift
Raw Normal View History

2021-09-25 13:48:22 +05:30
import Siesta
2021-06-12 04:19:42 +05:30
import SwiftUI
struct SubscriptionsView: View {
2021-09-25 13:48:22 +05:30
@StateObject private var store = Store<[Video]>()
2021-06-26 17:07:24 +05:30
2021-10-17 04:18:58 +05:30
@EnvironmentObject<AccountsModel> private var accounts
var api: InvidiousAPI {
accounts.invidious
}
2021-06-12 04:19:42 +05:30
2021-09-25 13:48:22 +05:30
var feed: Resource {
api.feed
2021-06-28 16:13:07 +05:30
}
2021-06-26 17:07:24 +05:30
2021-06-28 16:13:07 +05:30
var body: some View {
PlayerControlsView {
SignInRequiredView(title: "Subscriptions") {
VideosCellsVertical(videos: store.collection)
.onAppear {
loadResources()
}
.onChange(of: accounts.current) { _ in
loadResources(force: true)
}
}
2021-09-25 13:48:22 +05:30
}
.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 16:13:07 +05:30
}
2021-09-25 13:48:22 +05:30
} else {
loadFeed(force: force)
}
}
fileprivate func loadFeed(force: Bool = false) {
_ = force ? feed.load() : feed.loadIfNeeded()
2021-06-12 04:19:42 +05:30
}
}