Poll: Support hidden votesCount close #1354
This commit is contained in:
parent
ab5c6643b3
commit
2601764b28
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 +
|
||||
|
|
Loading…
Reference in New Issue