Added toggleable button to show/hide poll results + animations (#1877)

* Added toggleable button to show/hide poll results

* Animations and localizations

---------

Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
This commit is contained in:
Eric 2024-01-12 23:30:25 -08:00 committed by GitHub
parent 73a02db57f
commit 231b622f4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 260 additions and 10 deletions

View File

@ -67603,6 +67603,125 @@
}
}
},
"status.poll.hide-results" : {
"extractionState" : "manual",
"localizations" : {
"be" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"ca" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"de" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Hide Results"
}
},
"en-GB" : {
"stringUnit" : {
"state" : "translated",
"value" : "Hide Results"
}
},
"es" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"eu" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"fr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"it" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"ja" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"ko" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"nb" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"nl" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"pl" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"tr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"uk" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Hide Results"
}
}
}
},
"status.poll.n-votes %lld" : {
"extractionState" : "manual",
"localizations" : {
@ -68923,6 +69042,125 @@
}
}
},
"status.poll.show-results" : {
"extractionState" : "manual",
"localizations" : {
"be" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"ca" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"de" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Show Results"
}
},
"en-GB" : {
"stringUnit" : {
"state" : "translated",
"value" : "Show Results"
}
},
"es" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"eu" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"fr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"it" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"ja" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"ko" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"nb" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"nl" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"pl" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"tr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"uk" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Show Results"
}
}
}
},
"status.post-from-%@" : {
"extractionState" : "manual",
"localizations" : {

View File

@ -94,6 +94,7 @@ public struct StatusPollView: View {
Text("\(percentForOption(option: option))%")
.font(.scaledSubheadline)
}
.frame(height: .pollBarHeight)
}
}
.accessibilityElement(children: .combine)
@ -103,15 +104,25 @@ public struct StatusPollView: View {
.accessibilityAddTraits(isInteractive ? [] : .isStaticText)
.accessibilityRemoveTraits(isInteractive ? [] : .isButton)
}
if !viewModel.poll.expired, !(viewModel.poll.voted ?? false), !viewModel.votes.isEmpty {
Button("status.poll.send") {
Task {
do {
await viewModel.postVotes()
if !viewModel.poll.expired, !(viewModel.poll.voted ?? false) {
HStack {
if !viewModel.votes.isEmpty {
Button("status.poll.send") {
Task {
do {
await viewModel.postVotes()
}
}
}
.buttonStyle(.borderedProminent)
}
Button(viewModel.showResults ? "status.poll.hide-results" : "status.poll.show-results") {
withAnimation {
viewModel.showResults.toggle()
}
}
.buttonStyle(.bordered)
}
.buttonStyle(.bordered)
}
footerView
@ -181,6 +192,8 @@ public struct StatusPollView: View {
Spacer()
}
}
.transition(.asymmetric(insertion: .push(from: .leading),
removal: .push(from: .trailing)))
}
}
.foregroundColor(theme.tintColor.opacity(0.40))

View File

@ -11,10 +11,7 @@ import SwiftUI
var poll: Poll
var votes: [Int] = []
var showResults: Bool {
poll.ownVotes?.isEmpty == false || poll.expired
}
var showResults: Bool = false
public init(poll: Poll) {
self.poll = poll
@ -25,6 +22,7 @@ import SwiftUI
guard let client else { return }
do {
poll = try await client.get(endpoint: Polls.poll(id: poll.id))
showResults = poll.ownVotes?.isEmpty == false || poll.expired
votes = poll.ownVotes ?? []
} catch {}
}
@ -35,6 +33,7 @@ import SwiftUI
poll = try await client.post(endpoint: Polls.vote(id: poll.id, votes: votes))
withAnimation {
votes = poll.ownVotes ?? []
showResults = true
}
} catch {
print(error)