1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Views/PopularView.swift

57 lines
1.5 KiB
Swift
Raw Normal View History

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
@ObservedObject private var accounts = AccountsModel.shared
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
var videos: [ContentItem] {
ContentItem.array(of: store.collection)
}
2021-06-28 16:13:07 +05:30
var body: some View {
2022-12-11 03:07:14 +05:30
VerticalCells(items: videos)
.onAppear {
resource?.addObserver(store)
resource?.loadIfNeeded()
2022-01-07 04:30:40 +05:30
}
2022-12-11 03:07:14 +05:30
#if !os(tvOS)
.navigationTitle("Popular")
.background(
Button("Refresh") {
resource?.load()
}
.keyboardShortcut("r")
.opacity(0)
)
2022-01-07 04:30:40 +05:30
#endif
#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 {
DispatchQueue.main.async {
resource?.load()
}
}
.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
}
}