Fix display of multiple vote polls (#967)

Closes #952
This commit is contained in:
Peter-Josef Meisch 2023-02-21 07:05:21 +01:00 committed by GitHub
parent a2346413ec
commit 6aeb25885c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 47 additions and 10 deletions

View file

@ -421,6 +421,7 @@
"status.media.contextmenu.view-browser" = "Праглядзець у браўзэры";
"status.media.sensitive.show" = "Паказаць адчувальны кантэнт";
"status.poll.n-votes %lld" = "%lld галасоў";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Зачынены";
"status.poll.closes-in" = "Зачыніцца праз ";
"status.poll.duration" = "Працягласць апытання";

View file

@ -431,6 +431,7 @@
"status.media.contextmenu.view-browser" = "Mostra al navegador";
"status.media.sensitive.show" = "Mostra el contingut sensible";
"status.poll.n-votes %lld" = "%lld vots";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Finalitzada";
"status.poll.closes-in" = "Finalitza en";
"status.poll.duration" = "Durada de l'enquesta";

View file

@ -428,6 +428,7 @@
"status.media.contextmenu.view-browser" = "Im Browser anzeigen";
"status.media.sensitive.show" = "Sensiblen Inhalt zeigen";
"status.poll.n-votes %lld" = "%lld Stimmen";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Beendet";
"status.poll.closes-in" = "Endet in ";
"status.poll.duration" = "Umfragedauer";

View file

@ -432,6 +432,7 @@
"status.media.contextmenu.view-browser" = "View in Browser";
"status.media.sensitive.show" = "Show sensitive content";
"status.poll.n-votes %lld" = "%lld votes";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Closed";
"status.poll.closes-in" = "Closes in ";
"status.poll.duration" = "Poll Duration";

View file

@ -433,6 +433,7 @@
"status.media.contextmenu.view-browser" = "View in Browser";
"status.media.sensitive.show" = "Show sensitive content";
"status.poll.n-votes %lld" = "%lld votes";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Closed";
"status.poll.closes-in" = "Closes in ";
"status.poll.duration" = "Poll Duration";

View file

@ -433,6 +433,7 @@
"status.media.contextmenu.view-browser" = "Ver en navegador";
"status.media.sensitive.show" = "Mostrar contenido sensible";
"status.poll.n-votes %lld" = "%lld votos";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Cerrada";
"status.poll.closes-in" = "Acaba en ";
"status.poll.duration" = "Duración de la encuesta";

View file

@ -425,6 +425,8 @@
"status.media.contextmenu.share" = "Partekatu irudia";
"status.media.contextmenu.view-browser" = "Ikusi nabigatzailean";
"status.media.sensitive.show" = "Erakutsi eduki hunkigarria";
"status.poll.n-votes %lld" = "%lld votes";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Amaituta";
"status.poll.closes-in" = "Epemuga: ";
"status.poll.duration" = "Bozketaren iraupena";

View file

@ -428,6 +428,7 @@
"status.media.contextmenu.view-browser" = "Afficher dans le navigateur";
"status.media.sensitive.show" = "Afficher le contenu sensible";
"status.poll.n-votes %lld" = "%lld votes";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Fermé";
"status.poll.closes-in" = "Ferme dans";
"status.poll.duration" = "Durée du sondage";

View file

@ -433,6 +433,7 @@
"status.media.contextmenu.view-browser" = "Visualizza nel browser";
"status.media.sensitive.show" = "Mostra i contenuti sensibili";
"status.poll.n-votes %lld" = "%lld voti";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Chiuso";
"status.poll.closes-in" = "Si chiude in ";
"status.poll.duration" = "Durata del sondaggio";

View file

@ -432,6 +432,7 @@
"status.media.contextmenu.view-browser" = "ブラウザで見る";
"status.media.sensitive.show" = "センシティブな内容を表示する";
"status.poll.n-votes %lld" = "%lld 投票";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "投票終了";
"status.poll.closes-in" = "投票終了まで ";
"status.poll.duration" = "投票期間";

View file

@ -434,6 +434,7 @@
"status.media.contextmenu.view-browser" = "브라우저에서 보기";
"status.media.sensitive.show" = "민감한 미디어 표시하기";
"status.poll.n-votes %lld" = "%lld표";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "종료됨";
"status.poll.closes-in" = "종료까지 ";
"status.poll.duration" = "투표 기간";

View file

@ -432,6 +432,7 @@
"status.media.contextmenu.view-browser" = "Vis i nettleser";
"status.media.sensitive.show" = "Vis sensitivt innhold";
"status.poll.n-votes %lld" = "%lld stemmer";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Lukket";
"status.poll.closes-in" = "Lukkes om ";
"status.poll.duration" = "Avstemningens varighet";

View file

@ -426,6 +426,7 @@
"status.media.contextmenu.view-browser" = "Open in browser";
"status.media.sensitive.show" = "Toon gevoelige inhoud";
"status.poll.n-votes %lld" = "%lld stemmen";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Beëindigd";
"status.poll.closes-in" = "Eindigt over ";
"status.poll.duration" = "Pollduur";

View file

@ -427,6 +427,8 @@
"status.media.contextmenu.share" = "Udostępnij ten obrazek";
"status.media.contextmenu.view-browser" = "Zobacz w przeglądarce";
"status.media.sensitive.show" = "Pokaż wrażliwą zawartość";
"status.poll.n-votes %lld" = "%lld votes";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Zamknięty";
"status.poll.closes-in" = "Zostanie zakończony za ";
"status.poll.duration" = "Czas trwania sondażu";

View file

@ -432,6 +432,7 @@
"status.media.contextmenu.view-browser" = "Exibir no Navegador";
"status.media.sensitive.show" = "Exibir conteúdo sensível";
"status.poll.n-votes %lld" = "%lld votos";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Encerrado";
"status.poll.closes-in" = "Encerrado em ";
"status.poll.duration" = "Duração da votação";

View file

@ -428,6 +428,7 @@
"status.media.contextmenu.view-browser" = "Tarayıcıda göster";
"status.media.sensitive.show" = "Hassas içeriği göster";
"status.poll.n-votes %lld" = "%lld oy";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "Kapandı";
"status.poll.closes-in" = "Kapanacak ";
"status.poll.duration" = "Anket Süresi";

View file

@ -431,6 +431,7 @@
"status.media.contextmenu.view-browser" = "在浏览器中打开";
"status.media.sensitive.show" = "显示敏感内容";
"status.poll.n-votes %lld" = "%lld 投票";
"status.poll.n-votes-voters %lld %lld" = "%lld votes from %lld voters";
"status.poll.closed" = "已关闭";
"status.poll.closes-in" = "关闭于 ";
"status.poll.duration" = "投票持续时间";

View file

@ -24,9 +24,18 @@ public struct Poll: Codable, Equatable, Hashable {
public let expired: Bool
public let multiple: Bool
public let votesCount: Int
public let votersCount: Int?
public let voted: Bool?
public let ownVotes: [Int]?
public let options: [Option]
// the votersCount can be null according to the docs when multiple is false.
// Didn't find that to be true, but we make sure
public var safeVotersCount: Int {
get {
return votersCount ?? votesCount
}
}
}
public struct NullableString: Codable, Equatable, Hashable {

View file

@ -19,20 +19,25 @@ public struct StatusPollView: View {
}
private func widthForOption(option: Poll.Option, proxy: GeometryProxy) -> CGFloat {
if viewModel.poll.votesCount == 0 {
if viewModel.poll.safeVotersCount != 0 {
let totalWidth = proxy.frame(in: .local).width
return totalWidth * ratioForOption(option: option)
} else {
return 0
}
let totalWidth = proxy.frame(in: .local).width
let ratio = CGFloat(option.votesCount) / CGFloat(viewModel.poll.votesCount)
return totalWidth * ratio
}
private func percentForOption(option: Poll.Option) -> Int {
let percent = ratioForOption(option: option) * 100
return Int(round(percent))
}
private func percentForOption(option: Poll.Option) -> Int {
let ratio = (Float(option.votesCount) / Float(viewModel.poll.votesCount)) * 100
if ratio.isNaN {
return 0
private func ratioForOption(option: Poll.Option) -> CGFloat {
if viewModel.poll.safeVotersCount != 0 {
return CGFloat(option.votesCount) / CGFloat(viewModel.poll.safeVotersCount)
} else {
return 0.0
}
return Int(round(ratio))
}
private func isSelected(option: Poll.Option) -> Bool {
@ -101,7 +106,11 @@ public struct StatusPollView: View {
private var footerView: some View {
HStack(spacing: 0) {
Text("status.poll.n-votes \(viewModel.poll.votesCount)")
if viewModel.poll.multiple {
Text("status.poll.n-votes-voters \(viewModel.poll.votesCount) \(viewModel.poll.safeVotersCount)")
} else {
Text("status.poll.n-votes \(viewModel.poll.votesCount)")
}
Text("")
if viewModel.poll.expired {
Text("status.poll.closed")