Timeline: Enable jump to latest + in place refresh for all other timeline types

This commit is contained in:
Thomas Ricouard 2023-02-25 19:32:47 +01:00
parent 43cb5164d1
commit 151154b335
4 changed files with 17 additions and 7 deletions

View File

@ -26,7 +26,6 @@ struct IceCubesApp: App {
@StateObject private var sidebarRouterPath = RouterPath()
@State private var selectedTab: Tab = .timeline
@State private var selectSidebarItem: Tab? = .timeline
@State private var popToRootTab: Tab = .other
@State private var sideBarLoadedTabs: Set<Tab> = Set()

View File

@ -95,7 +95,7 @@ struct TimelineTab: View {
@ViewBuilder
private var timelineFilterButton: some View {
if timeline == .home {
if timeline.supportNewestPagination {
Button {
self.timeline = .latest
} label: {

View File

@ -103,7 +103,11 @@ public struct TimelineView: View {
.navigationBarTitleDisplayMode(.inline)
.onAppear {
viewModel.isTimelineVisible = true
viewModel.client = client
if viewModel.client == nil {
viewModel.client = client
}
viewModel.timeline = timeline
}
.onDisappear {

View File

@ -12,9 +12,9 @@ class TimelineViewModel: ObservableObject {
didSet {
timelineTask?.cancel()
timelineTask = Task {
if timeline == .latest, let client {
await cache.clearCache(for: client.id)
timeline = .home
if timeline == .latest {
await clearHomeCache()
timeline = oldValue
}
if oldValue != timeline {
await datasource.reset()
@ -68,7 +68,7 @@ class TimelineViewModel: ObservableObject {
}
var pendingStatusesEnabled: Bool {
timeline == .home
timeline.supportNewestPagination
}
var serverName: String {
@ -100,6 +100,7 @@ class TimelineViewModel: ObservableObject {
func handleEvent(event: any StreamEvent, currentAccount _: CurrentAccount) {
Task {
if let event = event as? StreamEventUpdate,
timeline == .home,
canStreamEvents,
isTimelineVisible,
pendingStatusesEnabled,
@ -151,6 +152,12 @@ extension TimelineViewModel {
}
return nil
}
private func clearHomeCache() async {
if let client, timeline == .home {
await cache.clearCache(for: client.id)
}
}
}
// MARK: - StatusesFetcher