mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 00:08:21 +00:00
57 lines
1.5 KiB
Swift
57 lines
1.5 KiB
Swift
import Siesta
|
|
import SwiftUI
|
|
|
|
struct PopularView: View {
|
|
@StateObject private var store = Store<[Video]>()
|
|
|
|
@ObservedObject private var accounts = AccountsModel.shared
|
|
|
|
var resource: Resource? {
|
|
accounts.api.popular
|
|
}
|
|
|
|
var videos: [ContentItem] {
|
|
ContentItem.array(of: store.collection)
|
|
}
|
|
|
|
var body: some View {
|
|
VerticalCells(items: videos)
|
|
.onAppear {
|
|
resource?.addObserver(store)
|
|
resource?.loadIfNeeded()
|
|
}
|
|
#if !os(tvOS)
|
|
.navigationTitle("Popular")
|
|
.background(
|
|
Button("Refresh") {
|
|
resource?.load()
|
|
}
|
|
.keyboardShortcut("r")
|
|
.opacity(0)
|
|
)
|
|
#endif
|
|
#if os(iOS)
|
|
.refreshControl { refreshControl in
|
|
resource?.load().onCompletion { _ in
|
|
refreshControl.endRefreshing()
|
|
}
|
|
.onFailure { error in
|
|
NavigationModel.shared.presentAlert(title: "Could not refresh Popular", message: error.userMessage)
|
|
}
|
|
}
|
|
.backport
|
|
.refreshable {
|
|
DispatchQueue.main.async {
|
|
resource?.load()
|
|
}
|
|
}
|
|
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
|
|
#endif
|
|
#if !os(macOS)
|
|
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
|
resource?.loadIfNeeded()
|
|
}
|
|
#endif
|
|
}
|
|
}
|