Handle errors when loading trending links
This commit is contained in:
parent
00a23b525f
commit
b63f663947
|
@ -126,16 +126,23 @@ class TrendingLinksViewController: UIViewController, CollectionViewController {
|
|||
snapshot.appendItems([.loadingIndicator])
|
||||
await dataSource.apply(snapshot)
|
||||
|
||||
do {
|
||||
let request = Client.getTrendingLinks()
|
||||
guard let (links, _) = try? await mastodonController.run(request) else {
|
||||
return
|
||||
}
|
||||
let (links, _) = try await mastodonController.run(request)
|
||||
snapshot.deleteSections([.loadingIndicator])
|
||||
snapshot.appendSections([.links])
|
||||
snapshot.appendItems(links.map { .link($0) })
|
||||
await dataSource.apply(snapshot)
|
||||
|
||||
state = .loaded
|
||||
} catch {
|
||||
await dataSource.apply(NSDiffableDataSourceSnapshot())
|
||||
state = .unloaded
|
||||
let config = ToastConfiguration(from: error, with: "Error Loading Trending Links", in: self) { [weak self] toast in
|
||||
toast.dismissToast(animated: true)
|
||||
await self?.loadInitial()
|
||||
}
|
||||
self.showToast(configuration: config, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
@ -165,15 +172,20 @@ class TrendingLinksViewController: UIViewController, CollectionViewController {
|
|||
await dataSource.apply(snapshot)
|
||||
}
|
||||
|
||||
let request = Client.getTrendingLinks(offset: snapshot.itemIdentifiers.count)
|
||||
guard let (links, _) = try? await mastodonController.run(request) else {
|
||||
return
|
||||
}
|
||||
do {
|
||||
let request = Client.getTrendingLinks(offset: origSnapshot.itemIdentifiers.count)
|
||||
let (links, _) = try await mastodonController.run(request)
|
||||
snapshot = origSnapshot
|
||||
snapshot.appendItems(links.map { .link($0) }, toSection: .links)
|
||||
await dataSource.apply(snapshot)
|
||||
|
||||
state = .loaded
|
||||
} catch {
|
||||
await dataSource.apply(origSnapshot)
|
||||
let config = ToastConfiguration(from: error, with: "Erorr Loading Older Links", in: self) { [weak self] toast in
|
||||
toast.dismissToast(animated: true)
|
||||
await self?.loadOlder()
|
||||
}
|
||||
self.showToast(configuration: config, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue