mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-29 20:56:57 +02:00
Fix: TimelinePoll code refactoring
This commit is contained in:
@@ -29,12 +29,12 @@ struct TimelinePollView: View {
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
switch viewModel.pollState {
|
||||
switch viewModel.viewState.pollState {
|
||||
case .loading:
|
||||
TimelinePollMessageView(message: "loading...")
|
||||
case .loaded:
|
||||
pollContent
|
||||
case .invalidStartEvent:
|
||||
TimelinePollMessageView(message: VectorL10n.pollTimelineLoading)
|
||||
case .loaded(let poll):
|
||||
pollContent(poll)
|
||||
case .errored:
|
||||
TimelinePollMessageView(message: VectorL10n.pollTimelineReplyEndedPoll)
|
||||
}
|
||||
}
|
||||
@@ -44,9 +44,7 @@ struct TimelinePollView: View {
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var pollContent: some View {
|
||||
let poll = viewModel.viewState.poll
|
||||
|
||||
private func pollContent(_ poll: TimelinePollDetails) -> some View {
|
||||
VStack(alignment: .leading, spacing: 16.0) {
|
||||
if poll.representsPollEndedEvent {
|
||||
Text(VectorL10n.pollTimelineEndedText)
|
||||
@@ -57,7 +55,7 @@ struct TimelinePollView: View {
|
||||
Text(poll.question)
|
||||
.font(theme.fonts.bodySB)
|
||||
.foregroundColor(theme.colors.primaryContent) +
|
||||
Text(editedText)
|
||||
Text(editedText(poll))
|
||||
.font(theme.fonts.footnote)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
|
||||
@@ -71,7 +69,7 @@ struct TimelinePollView: View {
|
||||
.disabled(poll.closed)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
|
||||
Text(totalVotesString)
|
||||
Text(totalVotesString(poll))
|
||||
.lineLimit(2)
|
||||
.font(theme.fonts.footnote)
|
||||
.foregroundColor(theme.colors.tertiaryContent)
|
||||
@@ -80,9 +78,7 @@ struct TimelinePollView: View {
|
||||
.padding([.bottom])
|
||||
}
|
||||
|
||||
private var totalVotesString: String {
|
||||
let poll = viewModel.viewState.poll
|
||||
|
||||
private func totalVotesString(_ poll: TimelinePollDetails) -> String {
|
||||
if poll.hasDecryptionError, poll.totalAnswerCount > 0 {
|
||||
return VectorL10n.pollTimelineDecryptionError
|
||||
}
|
||||
@@ -109,8 +105,8 @@ struct TimelinePollView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var editedText: String {
|
||||
viewModel.viewState.poll.hasBeenEdited ? " \(VectorL10n.eventFormatterMessageEditedMention)" : ""
|
||||
private func editedText(_ poll: TimelinePollDetails) -> String {
|
||||
poll.hasBeenEdited ? " \(VectorL10n.eventFormatterMessageEditedMention)" : ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user