mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-27 11:46:58 +02:00
Handle empty poll list case
This commit is contained in:
@@ -25,6 +25,8 @@ enum MockPollHistoryScreenState: MockScreenState, CaseIterable {
|
||||
// mock that screen.
|
||||
case active
|
||||
case past
|
||||
case activeEmpty
|
||||
case pastEmpty
|
||||
|
||||
/// The associated screen
|
||||
var screenType: Any.Type {
|
||||
@@ -34,15 +36,22 @@ enum MockPollHistoryScreenState: MockScreenState, CaseIterable {
|
||||
/// Generate the view struct for the screen state.
|
||||
var screenView: ([Any], AnyView) {
|
||||
let pollHistoryMode: PollHistoryMode
|
||||
let pollService = MockPollHistoryService()
|
||||
|
||||
switch self {
|
||||
case .active:
|
||||
pollHistoryMode = .active
|
||||
case .past:
|
||||
pollHistoryMode = .past
|
||||
case .activeEmpty:
|
||||
pollHistoryMode = .active
|
||||
pollService.pollListData = []
|
||||
case .pastEmpty:
|
||||
pollHistoryMode = .past
|
||||
pollService.pollListData = []
|
||||
}
|
||||
|
||||
let viewModel = PollHistoryViewModel(mode: pollHistoryMode, pollService: MockPollHistoryService())
|
||||
let viewModel = PollHistoryViewModel(mode: pollHistoryMode, pollService: pollService)
|
||||
|
||||
// can simulate service and viewModel actions here if needs be.
|
||||
|
||||
|
||||
@@ -15,13 +15,15 @@
|
||||
//
|
||||
|
||||
final class MockPollHistoryService: PollHistoryServiceProtocol {
|
||||
var pollListData: [PollListData] = (1..<10)
|
||||
.map { index in
|
||||
PollListData(startDate: .init().addingTimeInterval(-CGFloat(index) * 3600), question: "Do you like the poll number \(index)?")
|
||||
}
|
||||
.sorted { poll1, poll2 in
|
||||
poll1.startDate > poll2.startDate
|
||||
}
|
||||
|
||||
func fetchHistory() async throws -> [PollListData] {
|
||||
(1..<10)
|
||||
.map { index in
|
||||
PollListData(startDate: .init().addingTimeInterval(-CGFloat(index) * 3600), question: "Do you like the poll number \(index)?")
|
||||
}
|
||||
.sorted { poll1, poll2 in
|
||||
poll1.startDate > poll2.startDate
|
||||
}
|
||||
pollListData
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,24 +37,10 @@ struct PollHistory: View {
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
|
||||
ScrollView {
|
||||
LazyVStack(spacing: 32) {
|
||||
let enumeratedPolls = Array(viewModel.viewState.polls.enumerated())
|
||||
|
||||
ForEach(enumeratedPolls, id: \.offset) { _, pollData in
|
||||
PollListItem(pollData: pollData)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Button {
|
||||
#warning("handle action")
|
||||
} label: {
|
||||
Text("Load more polls")
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.top, 32)
|
||||
if viewModel.viewState.polls.isEmpty {
|
||||
noPollsView
|
||||
} else {
|
||||
pollListView
|
||||
}
|
||||
}
|
||||
.padding(.top, 32)
|
||||
@@ -66,6 +52,36 @@ struct PollHistory: View {
|
||||
viewModel.send(viewAction: .viewAppeared)
|
||||
}
|
||||
}
|
||||
|
||||
private var pollListView: some View {
|
||||
ScrollView {
|
||||
LazyVStack(spacing: 32) {
|
||||
let enumeratedPolls = Array(viewModel.viewState.polls.enumerated())
|
||||
|
||||
ForEach(enumeratedPolls, id: \.offset) { _, pollData in
|
||||
PollListItem(pollData: pollData)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Button {
|
||||
#warning("handle action")
|
||||
} label: {
|
||||
Text("Load more polls")
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.padding(.top, 32)
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
}
|
||||
|
||||
private var noPollsView: some View {
|
||||
Text(viewModel.mode == .active ? VectorL10n.pollHistoryNoActivePollText : VectorL10n.pollHistoryNoPastPollText)
|
||||
.font(theme.fonts.body)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
.frame(maxHeight: .infinity)
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
}
|
||||
|
||||
private extension PollHistoryMode {
|
||||
|
||||
Reference in New Issue
Block a user