2022-12-11 12:38:57 +01:00
|
|
|
import Defaults
|
|
|
|
import Siesta
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct FeedView: View {
|
|
|
|
@ObservedObject private var feed = FeedModel.shared
|
|
|
|
|
2022-12-13 12:09:20 +01:00
|
|
|
@Default(.showCacheStatus) private var showCacheStatus
|
|
|
|
|
2022-12-12 01:18:29 +01:00
|
|
|
#if os(tvOS)
|
|
|
|
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
|
|
|
|
#endif
|
|
|
|
|
2022-12-11 12:38:57 +01:00
|
|
|
var videos: [ContentItem] {
|
|
|
|
ContentItem.array(of: feed.videos)
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
2023-06-07 22:32:54 +02:00
|
|
|
VerticalCells(items: videos) { if shouldDisplayHeader { header } }
|
2022-12-13 20:15:00 +01:00
|
|
|
.environment(\.loadMoreContentHandler) { feed.loadNextPage() }
|
|
|
|
.onAppear {
|
|
|
|
feed.loadResources()
|
|
|
|
}
|
2022-12-11 12:38:57 +01:00
|
|
|
#if os(iOS)
|
2023-10-15 13:35:23 +02:00
|
|
|
.refreshControl { refreshControl in
|
|
|
|
feed.loadResources(force: true) {
|
|
|
|
refreshControl.endRefreshing()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.backport
|
2022-12-13 20:15:00 +01:00
|
|
|
.refreshable {
|
2023-10-15 13:46:30 +02:00
|
|
|
await feed.loadResources(force: true)
|
2022-12-11 12:38:57 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if !os(tvOS)
|
2023-06-17 14:09:51 +02:00
|
|
|
.background(
|
2022-12-11 12:38:57 +01:00
|
|
|
Button("Refresh") {
|
|
|
|
feed.loadResources(force: true)
|
|
|
|
}
|
|
|
|
.keyboardShortcut("r")
|
|
|
|
.opacity(0)
|
|
|
|
)
|
|
|
|
#endif
|
|
|
|
#if !os(macOS)
|
2023-06-17 14:09:51 +02:00
|
|
|
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
|
|
|
feed.loadResources()
|
2022-12-11 12:38:57 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2022-12-13 20:15:00 +01:00
|
|
|
|
|
|
|
var header: some View {
|
|
|
|
HStack {
|
|
|
|
#if os(tvOS)
|
|
|
|
SubscriptionsPageButton()
|
|
|
|
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
2023-05-23 18:48:39 +02:00
|
|
|
HideWatchedButtons()
|
2023-05-23 18:54:53 +02:00
|
|
|
HideShortsButtons()
|
2022-12-13 20:15:00 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if showCacheStatus {
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
CacheStatusHeader(
|
|
|
|
refreshTime: feed.formattedFeedTime,
|
|
|
|
isLoading: feed.isLoading
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#if os(tvOS)
|
|
|
|
Button {
|
|
|
|
feed.loadResources(force: true)
|
|
|
|
} label: {
|
|
|
|
Label("Refresh", systemImage: "arrow.clockwise")
|
|
|
|
.labelStyle(.iconOnly)
|
|
|
|
.imageScale(.small)
|
2023-04-22 21:07:30 +02:00
|
|
|
.font(.caption)
|
2022-12-13 20:15:00 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.padding(.leading, 30)
|
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.bottom, 15)
|
2023-02-25 16:42:18 +01:00
|
|
|
.padding(.trailing, 30)
|
2022-12-13 20:15:00 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
var shouldDisplayHeader: Bool {
|
|
|
|
#if os(tvOS)
|
|
|
|
true
|
|
|
|
#else
|
|
|
|
showCacheStatus
|
|
|
|
#endif
|
|
|
|
}
|
2022-12-11 12:38:57 +01:00
|
|
|
}
|
|
|
|
|
2023-02-25 16:42:18 +01:00
|
|
|
struct FeedView_Previews: PreviewProvider {
|
2022-12-11 12:38:57 +01:00
|
|
|
static var previews: some View {
|
|
|
|
NavigationView {
|
|
|
|
FeedView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|