2021-06-28 10:43:07 +00:00
|
|
|
import Siesta
|
2021-06-11 12:36:26 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
2021-07-27 22:40:04 +00:00
|
|
|
struct PopularView: View {
|
2021-09-25 08:18:22 +00:00
|
|
|
@StateObject private var store = Store<[Video]>()
|
2021-06-11 21:54:00 +00:00
|
|
|
|
2021-10-16 22:48:58 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
2021-06-11 21:11:59 +00:00
|
|
|
|
2021-10-20 22:21:50 +00:00
|
|
|
var resource: Resource? {
|
|
|
|
accounts.api.popular
|
2021-06-28 10:43:07 +00:00
|
|
|
}
|
2021-06-14 18:05:02 +00:00
|
|
|
|
2021-10-21 23:29:10 +00:00
|
|
|
var videos: [ContentItem] {
|
|
|
|
ContentItem.array(of: store.collection)
|
|
|
|
}
|
|
|
|
|
2021-06-28 10:43:07 +00:00
|
|
|
var body: some View {
|
2022-02-16 20:23:11 +00:00
|
|
|
BrowserPlayerControls {
|
2021-10-21 23:29:10 +00:00
|
|
|
VerticalCells(items: videos)
|
2021-10-05 20:20:09 +00:00
|
|
|
.onAppear {
|
2021-10-20 22:21:50 +00:00
|
|
|
resource?.addObserver(store)
|
|
|
|
resource?.loadIfNeeded()
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
#if !os(tvOS)
|
|
|
|
.navigationTitle("Popular")
|
|
|
|
#endif
|
|
|
|
}
|
2021-11-01 21:56:18 +00:00
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .automatic) {
|
|
|
|
FavoriteButton(item: FavoriteItem(section: .popular))
|
|
|
|
}
|
|
|
|
}
|
2022-01-06 23:00:40 +00:00
|
|
|
#if !os(tvOS)
|
|
|
|
.background(
|
|
|
|
Button("Refresh") {
|
|
|
|
resource?.load()
|
|
|
|
}
|
|
|
|
.keyboardShortcut("r")
|
2022-01-07 11:12:56 +00:00
|
|
|
.opacity(0)
|
2022-01-06 23:00:40 +00:00
|
|
|
)
|
|
|
|
#endif
|
2022-01-05 16:25:57 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.refreshControl { refreshControl in
|
|
|
|
resource?.load().onCompletion { _ in
|
|
|
|
refreshControl.endRefreshing()
|
|
|
|
}
|
2022-09-02 17:02:19 +00:00
|
|
|
.onFailure { error in
|
|
|
|
NavigationModel.shared.presentAlert(title: "Could not refresh Trending", message: error.userMessage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.backport
|
|
|
|
.refreshable {
|
2022-09-04 15:24:07 +00:00
|
|
|
DispatchQueue.main.async {
|
|
|
|
resource?.load()
|
|
|
|
}
|
2022-01-05 16:25:57 +00:00
|
|
|
}
|
|
|
|
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
|
|
|
|
#endif
|
2022-08-28 18:00:43 +00:00
|
|
|
#if !os(macOS)
|
|
|
|
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
|
|
|
resource?.loadIfNeeded()
|
|
|
|
}
|
|
|
|
#endif
|
2021-06-11 12:36:26 +00:00
|
|
|
}
|
|
|
|
}
|