Poll: Support hidden votesCount close #1354

This commit is contained in:
Thomas Ricouard 2023-04-04 08:03:33 +02:00
parent ab5c6643b3
commit 2601764b28
3 changed files with 5 additions and 5 deletions

View file

@ -16,7 +16,7 @@ public struct Poll: Codable, Equatable, Hashable {
public var id = UUID().uuidString
public let title: String
public let votesCount: Int
public let votesCount: Int?
}
public let id: String

View file

@ -33,8 +33,8 @@ public struct StatusPollView: View {
}
private func ratioForOption(option: Poll.Option) -> CGFloat {
if viewModel.poll.safeVotersCount != 0 {
return CGFloat(option.votesCount) / CGFloat(viewModel.poll.safeVotersCount)
if let votesCount = option.votesCount, viewModel.poll.safeVotersCount != 0 {
return CGFloat(votesCount) / CGFloat(viewModel.poll.safeVotersCount)
} else {
return 0.0
}

View file

@ -335,8 +335,8 @@ private struct CombinedAccessibilityLabel {
return poll.options.enumerated().reduce(into: Text(title)) { text, pair in
let (index, option) = pair
let selected = poll.ownVotes?.contains(index) ?? false
let percentage = poll.safeVotersCount > 0
? Int(round(Double(option.votesCount) / Double(poll.safeVotersCount) * 100))
let percentage = poll.safeVotersCount > 0 && option.votesCount != nil
? Int(round(Double(option.votesCount!) / Double(poll.safeVotersCount) * 100))
: 0
text = text +