Timeline: Dequeue one

This commit is contained in:
Thomas Ricouard 2023-01-05 07:07:28 +01:00
parent 511717e492
commit 88b56fe016
2 changed files with 32 additions and 9 deletions

View file

@ -109,17 +109,31 @@ public struct TimelineView: View {
@ViewBuilder @ViewBuilder
private func makePendingNewPostsView(proxy: ScrollViewProxy) -> some View { private func makePendingNewPostsView(proxy: ScrollViewProxy) -> some View {
if !viewModel.pendingStatuses.isEmpty { if !viewModel.pendingStatuses.isEmpty {
Button { HStack(spacing: 6) {
withAnimation { Button {
proxy.scrollTo(Constants.scrollToTop) withAnimation {
viewModel.displayPendingStatuses() proxy.scrollTo(Constants.scrollToTop)
viewModel.displayPendingStatuses()
}
} label: {
Text(viewModel.pendingStatusesButtonTitle)
}
.buttonStyle(.bordered)
.background(.thinMaterial)
.cornerRadius(8)
if viewModel.pendingStatuses.count > 1 {
Button {
withAnimation {
viewModel.dequeuePendingStatuses()
}
} label: {
Image(systemName: "play.square.stack")
}
.buttonStyle(.bordered)
.background(.thinMaterial)
.cornerRadius(8)
} }
} label: {
Text(viewModel.pendingStatusesButtonTitle)
} }
.buttonStyle(.bordered)
.background(.thinMaterial)
.cornerRadius(8)
.padding(.top, 6) .padding(.top, 6)
} }
} }

View file

@ -179,4 +179,13 @@ class TimelineViewModel: ObservableObject, StatusesFetcher {
pendingStatuses = [] pendingStatuses = []
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage) statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
} }
func dequeuePendingStatuses() {
guard timeline == .home else { return }
if pendingStatuses.count > 1 {
let status = pendingStatuses.removeLast()
statuses.insert(status, at: 0)
}
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
}
} }