show progress view on web reader if content doesn't load in one second

This commit is contained in:
Satindar Dhillon 2022-05-04 14:48:12 -07:00
parent a657da2b5f
commit 4279bed74d
2 changed files with 14 additions and 5 deletions

View file

@ -15,6 +15,7 @@ import WebKit
@State private var navBarVisibilityRatio = 1.0
@State private var showDeleteConfirmation = false
@State private var showOverlay = true
@State private var progressViewOpacity = 0.0
@State var increaseFontActionID: UUID?
@State var decreaseFontActionID: UUID?
@State var annotationSaveTransactionID: UUID?
@ -186,9 +187,16 @@ import WebKit
}
)
}
} else if let errorMessage = viewModel.errorMessage {
Text(errorMessage).padding()
} else {
Text(viewModel.contentFetchFailed ? "Unable to fetch content." : "Processing...")
.padding()
ProgressView()
.opacity(progressViewOpacity)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1000)) {
progressViewOpacity = 1
}
}
.task {
await viewModel.loadContent(dataService: dataService, itemID: item.unwrappedID)
}

View file

@ -10,15 +10,16 @@ struct SafariWebLink: Identifiable {
@MainActor final class WebReaderViewModel: ObservableObject {
@Published var articleContent: ArticleContent?
@Published var contentFetchFailed = false
@Published var errorMessage: String?
func loadContent(dataService: DataService, itemID: String) async {
contentFetchFailed = false
errorMessage = nil
do {
articleContent = try await dataService.fetchArticleContent(itemID: itemID)
} catch {
contentFetchFailed = true
// TODO: check if this is a network or parsing error
errorMessage = "Unable to extract your content."
}
}