Timeline: Fix trending refreshing when navigating back

This commit is contained in:
Thomas Ricouard 2023-02-27 18:41:51 +01:00
parent 6dcce79379
commit 4bc2672583
2 changed files with 10 additions and 4 deletions

View File

@ -115,7 +115,7 @@ public struct TimelineView: View {
}
.refreshable {
HapticManager.shared.fireHaptic(of: .dataRefresh(intensity: 0.3))
await viewModel.fetchNewestStatuses()
await viewModel.pullToRefresh()
HapticManager.shared.fireHaptic(of: .dataRefresh(intensity: 0.7))
}
.onChange(of: watcher.latestEvent?.id) { _ in

View File

@ -156,13 +156,19 @@ extension TimelineViewModel {
// MARK: - StatusesFetcher
extension TimelineViewModel: StatusesFetcher {
func pullToRefresh() async {
if !timeline.supportNewestPagination {
await reset()
}
await fetchNewestStatuses()
}
func fetchNewestStatuses() async {
guard let client else { return }
do {
if await datasource.isEmpty || !timeline.supportNewestPagination {
await reset()
if await datasource.isEmpty {
try await fetchFirstPage(client: client)
} else if let latest = await datasource.get().first {
} else if let latest = await datasource.get().first, timeline.supportNewestPagination {
try await fetchNewPagesFrom(latestStatus: latest, client: client)
}
} catch {