diff --git a/IceCubesApp/Resources/Localization/Localizable.xcstrings b/IceCubesApp/Resources/Localization/Localizable.xcstrings index 901eaa4d..7d7db848 100644 --- a/IceCubesApp/Resources/Localization/Localizable.xcstrings +++ b/IceCubesApp/Resources/Localization/Localizable.xcstrings @@ -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" : { diff --git a/Packages/StatusKit/Sources/StatusKit/Poll/StatusPollView.swift b/Packages/StatusKit/Sources/StatusKit/Poll/StatusPollView.swift index e89da702..b97608c5 100644 --- a/Packages/StatusKit/Sources/StatusKit/Poll/StatusPollView.swift +++ b/Packages/StatusKit/Sources/StatusKit/Poll/StatusPollView.swift @@ -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)) diff --git a/Packages/StatusKit/Sources/StatusKit/Poll/StatusPollViewModel.swift b/Packages/StatusKit/Sources/StatusKit/Poll/StatusPollViewModel.swift index 4a8bfe8f..2b3c023c 100644 --- a/Packages/StatusKit/Sources/StatusKit/Poll/StatusPollViewModel.swift +++ b/Packages/StatusKit/Sources/StatusKit/Poll/StatusPollViewModel.swift @@ -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)