yattee/Shared/Watch Now/WatchNowSection.swift

29 lines
681 B
Swift
Raw Normal View History

2021-09-25 08:18:22 +00:00
import Defaults
2021-09-18 20:36:42 +00:00
import Siesta
import SwiftUI
struct WatchNowSection: View {
2021-10-20 22:21:50 +00:00
let resource: Resource?
2021-09-18 20:36:42 +00:00
let label: String
2021-09-25 08:18:22 +00:00
@StateObject private var store = Store<[Video]>()
2021-10-16 22:48:58 +00:00
@EnvironmentObject<AccountsModel> private var accounts
2021-09-25 08:18:22 +00:00
2021-10-20 22:21:50 +00:00
init(resource: Resource?, label: String) {
2021-09-18 20:36:42 +00:00
self.resource = resource
self.label = label
}
var body: some View {
WatchNowSectionBody(label: label, videos: store.collection)
.onAppear {
2021-10-20 22:21:50 +00:00
resource?.addObserver(store)
resource?.loadIfNeeded()
2021-09-25 08:18:22 +00:00
}
.onChange(of: accounts.current) { _ in
2021-10-20 22:21:50 +00:00
resource?.load()
2021-09-18 20:36:42 +00:00
}
}
}