forked from shadowfacts/Tusker
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])
|
snapshot.appendItems([.loadingIndicator])
|
||||||
await dataSource.apply(snapshot)
|
await dataSource.apply(snapshot)
|
||||||
|
|
||||||
|
do {
|
||||||
let request = Client.getTrendingLinks()
|
let request = Client.getTrendingLinks()
|
||||||
guard let (links, _) = try? await mastodonController.run(request) else {
|
let (links, _) = try await mastodonController.run(request)
|
||||||
return
|
|
||||||
}
|
|
||||||
snapshot.deleteSections([.loadingIndicator])
|
snapshot.deleteSections([.loadingIndicator])
|
||||||
snapshot.appendSections([.links])
|
snapshot.appendSections([.links])
|
||||||
snapshot.appendItems(links.map { .link($0) })
|
snapshot.appendItems(links.map { .link($0) })
|
||||||
await dataSource.apply(snapshot)
|
await dataSource.apply(snapshot)
|
||||||
|
|
||||||
state = .loaded
|
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
|
@MainActor
|
||||||
|
@ -165,15 +172,20 @@ class TrendingLinksViewController: UIViewController, CollectionViewController {
|
||||||
await dataSource.apply(snapshot)
|
await dataSource.apply(snapshot)
|
||||||
}
|
}
|
||||||
|
|
||||||
let request = Client.getTrendingLinks(offset: snapshot.itemIdentifiers.count)
|
do {
|
||||||
guard let (links, _) = try? await mastodonController.run(request) else {
|
let request = Client.getTrendingLinks(offset: origSnapshot.itemIdentifiers.count)
|
||||||
return
|
let (links, _) = try await mastodonController.run(request)
|
||||||
}
|
|
||||||
snapshot = origSnapshot
|
snapshot = origSnapshot
|
||||||
snapshot.appendItems(links.map { .link($0) }, toSection: .links)
|
snapshot.appendItems(links.map { .link($0) }, toSection: .links)
|
||||||
await dataSource.apply(snapshot)
|
await dataSource.apply(snapshot)
|
||||||
|
} catch {
|
||||||
state = .loaded
|
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