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