Add live synced days

This commit is contained in:
Alfonso Grillo
2023-01-25 15:12:19 +01:00
parent 1f953c8a93
commit 94ca5e3ccc
5 changed files with 41 additions and 11 deletions
@@ -83,7 +83,7 @@ private extension PollHistoryViewModel {
switch completion {
case .finished:
state.numberOfFetchedBatches += 1
break
case .failure(_):
#warning("Handle errors")
}
@@ -106,6 +106,11 @@ private extension PollHistoryViewModel {
#warning("Handle errors")
}
.store(in: &subcriptions)
pollService
.fetchedUpTo
.weakAssign(to: \.state.syncedUpTo, on: self)
.store(in: &subcriptions)
}
func update(poll: TimelinePollDetails) {
@@ -136,17 +141,20 @@ private extension PollHistoryViewModel {
extension PollHistoryViewModel.Context {
var emptyPollsText: String {
let days = PollHistoryConstants.chunkSizeInDays * viewState.numberOfFetchedBatches
switch (viewState.bindings.mode, viewState.canLoadMoreContent) {
case (.active, true):
return VectorL10n.pollHistoryNoActivePollPeriodText("\(days)")
return VectorL10n.pollHistoryNoActivePollPeriodText("\(syncedPastDays)")
case (.active, false):
return VectorL10n.pollHistoryNoActivePollText
case (.past, true):
return VectorL10n.pollHistoryNoPastPollPeriodText("\(days)")
return VectorL10n.pollHistoryNoPastPollPeriodText("\(syncedPastDays)")
case (.past, false):
return VectorL10n.pollHistoryNoPastPollText
}
}
var syncedPastDays: UInt {
let timeDelta = max(viewState.syncStartDate.timeIntervalSince(viewState.syncedUpTo), 0)
return UInt((timeDelta / PollHistoryConstants.oneDayInSeconds).rounded())
}
}