Add emptyPollsText in the view model

This commit is contained in:
Alfonso Grillo
2023-01-24 09:47:50 +01:00
parent 562928507f
commit 22cca234be
3 changed files with 26 additions and 19 deletions
@@ -101,3 +101,20 @@ private extension PollHistoryViewModel {
state.polls = renderedPolls?.sorted(by: { $0.startDate > $1.startDate })
}
}
extension PollHistoryViewModel.Context {
var emptyPollsText: String {
let days = PollHistoryConstants.chunkSizeInDays
switch (viewState.bindings.mode, viewState.canLoadMoreContent) {
case (.active, true):
return VectorL10n.pollHistoryNoActivePollPeriodText("\(days)")
case (.active, false):
return VectorL10n.pollHistoryNoActivePollText
case (.past, true):
return VectorL10n.pollHistoryNoPastPollPeriodText("\(days)")
case (.past, false):
return VectorL10n.pollHistoryNoPastPollText
}
}
}
@@ -53,7 +53,7 @@ final class PollHistoryUITests: MockScreenTestCase {
func testPastPollHistoryIsEmpty() {
app.goToScreenWithIdentifier(MockPollHistoryScreenState.pastEmpty.title)
let title = app.navigationBars.firstMatch.identifier
let emptyText = app.staticTexts["PollHistory.emptyLoadMoreText"]
let emptyText = app.staticTexts["PollHistory.emptyText"]
let items = app.staticTexts["PollListItem.title"]
let selectedSegment = app.buttons[VectorL10n.pollHistoryPastSegmentTitle]
let winningOption = app.staticTexts["PollListData.winningOption"]
@@ -94,30 +94,20 @@ struct PollHistory: View {
.progressViewStyle(CircularProgressViewStyle())
}
@ViewBuilder
private var noPollsView: some View {
if viewModel.viewState.canLoadMoreContent {
let days = PollHistoryConstants.chunkSizeInDays
VStack(spacing: 32) {
Text(viewModel.mode == .active ? VectorL10n.pollHistoryNoActivePollPeriodText("\(days)") : VectorL10n.pollHistoryNoPastPollPeriodText("\(days)"))
.font(theme.fonts.body)
.foregroundColor(theme.colors.secondaryContent)
.multilineTextAlignment(.center)
.padding(.horizontal, 16)
.accessibilityIdentifier("PollHistory.emptyLoadMoreText")
loadMoreButton
}
.frame(maxHeight: .infinity)
} else {
Text(viewModel.mode == .active ? VectorL10n.pollHistoryNoActivePollText : VectorL10n.pollHistoryNoPastPollText)
VStack(spacing: 32) {
Text(viewModel.emptyPollsText)
.font(theme.fonts.body)
.multilineTextAlignment(.center)
.foregroundColor(theme.colors.secondaryContent)
.frame(maxHeight: .infinity)
.padding(.horizontal, 16)
.accessibilityIdentifier("PollHistory.emptyText")
if viewModel.viewState.canLoadMoreContent {
loadMoreButton
}
}
.frame(maxHeight: .infinity)
}
private var loadingView: some View {