mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Feed cache
This commit is contained in:
24
Shared/Views/CacheStatusHeader.swift
Normal file
24
Shared/Views/CacheStatusHeader.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
import SwiftUI
|
||||
|
||||
struct CacheStatusHeader: View {
|
||||
var refreshTime: String
|
||||
var isLoading = false
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 6) {
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
.scaleEffect(Constants.progressViewScale, anchor: .center)
|
||||
.opacity(isLoading ? 1 : 0)
|
||||
Text(refreshTime)
|
||||
}
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
struct CacheStatusHeader_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
CacheStatusHeader(refreshTime: "15:10:20")
|
||||
}
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct SubscriptionsView: View {
|
||||
@StateObject private var store = Store<[Video]>()
|
||||
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
var feed: Resource? {
|
||||
accounts.api.feed
|
||||
}
|
||||
|
||||
var videos: [ContentItem] {
|
||||
ContentItem.array(of: store.collection)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
BrowserPlayerControls {
|
||||
SignInRequiredView(title: "Subscriptions".localized()) {
|
||||
VerticalCells(items: videos)
|
||||
.onAppear {
|
||||
loadResources()
|
||||
}
|
||||
.onChange(of: accounts.current) { _ in
|
||||
loadResources(force: true)
|
||||
}
|
||||
#if os(iOS)
|
||||
.refreshControl { refreshControl in
|
||||
loadResources(force: true) {
|
||||
refreshControl.endRefreshing()
|
||||
}
|
||||
}
|
||||
.backport
|
||||
.refreshable {
|
||||
await loadResources(force: true)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if !os(tvOS)
|
||||
.background(
|
||||
Button("Refresh") {
|
||||
loadResources(force: true)
|
||||
}
|
||||
.keyboardShortcut("r")
|
||||
.opacity(0)
|
||||
)
|
||||
#endif
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
|
||||
#endif
|
||||
#if !os(macOS)
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
||||
loadResources()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private func loadResources(force: Bool = false, onCompletion: @escaping () -> Void = {}) {
|
||||
feed?.addObserver(store)
|
||||
|
||||
if accounts.app == .invidious {
|
||||
// Invidious for some reason won't refresh feed until homepage is loaded
|
||||
if let request = force ? accounts.api.home?.load() : accounts.api.home?.loadIfNeeded() {
|
||||
request.onSuccess { _ in
|
||||
loadFeed(force: force, onCompletion: onCompletion)
|
||||
}
|
||||
} else {
|
||||
loadFeed(force: force, onCompletion: onCompletion)
|
||||
}
|
||||
} else {
|
||||
loadFeed(force: force, onCompletion: onCompletion)
|
||||
}
|
||||
}
|
||||
|
||||
private func loadFeed(force: Bool = false, onCompletion: @escaping () -> Void = {}) {
|
||||
if let request = force ? feed?.load() : feed?.loadIfNeeded() {
|
||||
request.onCompletion { _ in
|
||||
onCompletion()
|
||||
}
|
||||
.onFailure { error in
|
||||
NavigationModel.shared.presentAlert(title: "Could not refresh Subscriptions", message: error.userMessage)
|
||||
}
|
||||
} else {
|
||||
onCompletion()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SubscriptonsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SubscriptionsView()
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user