mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
Add poll history service
This commit is contained in:
@@ -39,8 +39,10 @@ struct PollHistory: View {
|
||||
|
||||
ScrollView {
|
||||
LazyVStack(spacing: 32) {
|
||||
ForEach(0..<10) { index in
|
||||
PollListItem(data: .init(startDate: Date(), question: "Poll question number \(index)"))
|
||||
let enumeratedPolls = Array(viewModel.viewState.polls.enumerated())
|
||||
|
||||
ForEach(enumeratedPolls, id: \.offset) { _, pollData in
|
||||
PollListItem(pollData: pollData)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
@@ -60,10 +62,13 @@ struct PollHistory: View {
|
||||
.background(theme.colors.background.ignoresSafeArea())
|
||||
.accentColor(theme.colors.accent)
|
||||
.navigationTitle(VectorL10n.pollHistoryTitle)
|
||||
.onAppear {
|
||||
viewModel.send(viewAction: .viewAppeared)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension PollHistoryMode {
|
||||
private extension PollHistoryMode {
|
||||
var segmentTitle: String {
|
||||
switch self {
|
||||
case .active:
|
||||
|
||||
@@ -24,33 +24,52 @@ struct PollListData {
|
||||
struct PollListItem: View {
|
||||
@Environment(\.theme) private var theme
|
||||
|
||||
private let data: PollListData
|
||||
private let pollData: PollListData
|
||||
|
||||
init(data: PollListData) {
|
||||
self.data = data
|
||||
init(pollData: PollListData) {
|
||||
self.pollData = pollData
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text(data.startDate.description)
|
||||
Text(pollData.formattedDate)
|
||||
.foregroundColor(theme.colors.tertiaryContent)
|
||||
.font(theme.fonts.caption1)
|
||||
|
||||
HStack(spacing: 8) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 8) {
|
||||
Image(uiImage: Asset.Images.pollHistory.image)
|
||||
.resizable()
|
||||
.frame(width: 16, height: 16)
|
||||
|
||||
Text(data.question)
|
||||
Text(pollData.question)
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
.font(theme.fonts.body)
|
||||
.lineLimit(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PollListItem_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
PollListItem(data: .init(startDate: .init(), question: "Did you like this poll?"))
|
||||
private extension PollListData {
|
||||
var formattedDate: String {
|
||||
DateFormatter.shortDateFormatter.string(from: startDate)
|
||||
}
|
||||
}
|
||||
|
||||
private extension DateFormatter {
|
||||
static let shortDateFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
formatter.timeStyle = .none
|
||||
formatter.dateStyle = .short
|
||||
formatter.timeZone = .init(identifier: "UTC")
|
||||
return formatter
|
||||
}()
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct PollListItem_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
PollListItem(pollData: .init(startDate: .init(), question: "Did you like this poll?"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user