diff --git a/Shared/Subscriptions/FeedView.swift b/Shared/Subscriptions/FeedView.swift index 2a8b51b8..ddcea0a5 100644 --- a/Shared/Subscriptions/FeedView.swift +++ b/Shared/Subscriptions/FeedView.swift @@ -17,59 +17,25 @@ struct FeedView: View { } var body: some View { - VerticalCells(items: videos) { - HStack { - #if os(tvOS) - SubscriptionsPageButton() - ListingStyleButtons(listingStyle: $subscriptionsListingStyle) - #endif - - if showCacheStatus { - Spacer() - - CacheStatusHeader( - refreshTime: feed.formattedFeedTime, - isLoading: feed.isLoading - ) - } - - #if os(tvOS) - if !showCacheStatus { - Spacer() - } - Button { - feed.loadResources(force: true) - } label: { - Label("Refresh", systemImage: "arrow.clockwise") - .labelStyle(.iconOnly) - .imageScale(.small) - .font(.caption2) - } - #endif + VerticalCells(items: videos) { if shouldDisplayHeader { header } } + .environment(\.loadMoreContentHandler) { feed.loadNextPage() } + .onAppear { + feed.loadResources() + } + .onChange(of: accounts.current) { _ in + feed.reset() + feed.loadResources(force: true) } - .padding(.leading, 30) - #if os(tvOS) - .padding(.bottom, 15) - #endif - } - .environment(\.loadMoreContentHandler) { feed.loadNextPage() } - .onAppear { - feed.loadResources() - } - .onChange(of: accounts.current) { _ in - feed.reset() - feed.loadResources(force: true) - } #if os(iOS) - .refreshControl { refreshControl in - feed.loadResources(force: true) { - refreshControl.endRefreshing() + .refreshControl { refreshControl in + feed.loadResources(force: true) { + refreshControl.endRefreshing() + } + } + .backport + .refreshable { + await feed.loadResources(force: true) } - } - .backport - .refreshable { - await feed.loadResources(force: true) - } #endif #if !os(tvOS) .background( @@ -86,6 +52,50 @@ struct FeedView: View { } #endif } + + var header: some View { + HStack { + #if os(tvOS) + SubscriptionsPageButton() + ListingStyleButtons(listingStyle: $subscriptionsListingStyle) + #endif + + if showCacheStatus { + Spacer() + + CacheStatusHeader( + refreshTime: feed.formattedFeedTime, + isLoading: feed.isLoading + ) + } + + #if os(tvOS) + if !showCacheStatus { + Spacer() + } + Button { + feed.loadResources(force: true) + } label: { + Label("Refresh", systemImage: "arrow.clockwise") + .labelStyle(.iconOnly) + .imageScale(.small) + .font(.caption2) + } + #endif + } + .padding(.leading, 30) + #if os(tvOS) + .padding(.bottom, 15) + #endif + } + + var shouldDisplayHeader: Bool { + #if os(tvOS) + true + #else + showCacheStatus + #endif + } } struct SubscriptonsView_Previews: PreviewProvider {