2022-12-11 11:38:57 +00:00
|
|
|
import Defaults
|
|
|
|
import Siesta
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct FeedView: View {
|
|
|
|
@ObservedObject private var feed = FeedModel.shared
|
|
|
|
|
2022-12-13 11:09:20 +00:00
|
|
|
@Default(.showCacheStatus) private var showCacheStatus
|
|
|
|
|
2022-12-12 00:18:29 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
|
|
|
|
#endif
|
|
|
|
|
2022-12-11 11:38:57 +00:00
|
|
|
var videos: [ContentItem] {
|
|
|
|
ContentItem.array(of: feed.videos)
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
2023-06-07 20:32:54 +00:00
|
|
|
VerticalCells(items: videos) { if shouldDisplayHeader { header } }
|
2022-12-13 19:15:00 +00:00
|
|
|
.environment(\.loadMoreContentHandler) { feed.loadNextPage() }
|
|
|
|
.onAppear {
|
|
|
|
feed.loadResources()
|
|
|
|
}
|
2022-12-11 11:38:57 +00:00
|
|
|
#if os(iOS)
|
2022-12-13 19:15:00 +00:00
|
|
|
.refreshable {
|
2023-09-23 13:15:21 +00:00
|
|
|
feed.loadResources(force: true)
|
2022-12-11 11:38:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if !os(tvOS)
|
2023-06-17 12:09:51 +00:00
|
|
|
.background(
|
2022-12-11 11:38:57 +00:00
|
|
|
Button("Refresh") {
|
|
|
|
feed.loadResources(force: true)
|
|
|
|
}
|
|
|
|
.keyboardShortcut("r")
|
|
|
|
.opacity(0)
|
|
|
|
)
|
|
|
|
#endif
|
|
|
|
#if !os(macOS)
|
2023-06-17 12:09:51 +00:00
|
|
|
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
|
|
|
feed.loadResources()
|
2022-12-11 11:38:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2022-12-13 19:15:00 +00:00
|
|
|
|
|
|
|
var header: some View {
|
|
|
|
HStack {
|
|
|
|
#if os(tvOS)
|
|
|
|
SubscriptionsPageButton()
|
|
|
|
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
2023-05-23 16:48:39 +00:00
|
|
|
HideWatchedButtons()
|
2023-05-23 16:54:53 +00:00
|
|
|
HideShortsButtons()
|
2022-12-13 19:15:00 +00: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 19:07:30 +00:00
|
|
|
.font(.caption)
|
2022-12-13 19:15:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.padding(.leading, 30)
|
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.bottom, 15)
|
2023-02-25 15:42:18 +00:00
|
|
|
.padding(.trailing, 30)
|
2022-12-13 19:15:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
var shouldDisplayHeader: Bool {
|
|
|
|
#if os(tvOS)
|
|
|
|
true
|
|
|
|
#else
|
|
|
|
showCacheStatus
|
|
|
|
#endif
|
|
|
|
}
|
2022-12-11 11:38:57 +00:00
|
|
|
}
|
|
|
|
|
2023-02-25 15:42:18 +00:00
|
|
|
struct FeedView_Previews: PreviewProvider {
|
2022-12-11 11:38:57 +00:00
|
|
|
static var previews: some View {
|
|
|
|
NavigationView {
|
|
|
|
FeedView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|