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