diff --git a/RiotSwiftUI/Modules/Room/PollEditForm/Coordinator/PollEditFormCoordinator.swift b/RiotSwiftUI/Modules/Room/PollEditForm/Coordinator/PollEditFormCoordinator.swift index 1c6c7f569..17bcf2548 100644 --- a/RiotSwiftUI/Modules/Room/PollEditForm/Coordinator/PollEditFormCoordinator.swift +++ b/RiotSwiftUI/Modules/Room/PollEditForm/Coordinator/PollEditFormCoordinator.swift @@ -39,7 +39,7 @@ final class PollEditFormCoordinator: Coordinator, Presentable { } // MARK: Public - + var childCoordinators: [Coordinator] = [] var completion: (() -> Void)? @@ -54,15 +54,12 @@ final class PollEditFormCoordinator: Coordinator, Presentable { if let startEvent = parameters.pollStartEvent, let pollContent = MXEventContentPollStart(fromJSON: startEvent.content) { viewModel = PollEditFormViewModel(parameters: PollEditFormViewModelParameters(mode: .editing, - pollDetails: PollDetails(type: Self.pollKindKeyToDetailsType(pollContent.kind), - question: pollContent.question, - answerOptions: pollContent.answerOptions.map { $0.text }))) + pollDetails: EditFormPollDetails(type: Self.pollKindKeyToDetailsType(pollContent.kind), + question: pollContent.question, + answerOptions: pollContent.answerOptions.map { $0.text }))) } else { - viewModel = PollEditFormViewModel(parameters: PollEditFormViewModelParameters(mode: .creation, - pollDetails: PollDetails(type: .disclosed, - question: "", - answerOptions: ["", ""]))) + viewModel = PollEditFormViewModel(parameters: PollEditFormViewModelParameters(mode: .creation, pollDetails: .default)) } let view = PollEditForm(viewModel: viewModel.context) @@ -140,7 +137,7 @@ final class PollEditFormCoordinator: Coordinator, Presentable { // MARK: - Private - private func buildPollContentWithDetails(_ details: PollDetails) -> MXEventContentPollStart { + private func buildPollContentWithDetails(_ details: EditFormPollDetails) -> MXEventContentPollStart { var options = [MXEventContentPollStartAnswerOption]() for answerOption in details.answerOptions { options.append(MXEventContentPollStartAnswerOption(uuid: UUID().uuidString, text: answerOption)) @@ -153,17 +150,17 @@ final class PollEditFormCoordinator: Coordinator, Presentable { } - private static func pollDetailsTypeToKindKey(_ type: PollEditFormType) -> String { - let mapping = [PollEditFormType.disclosed : kMXMessageContentKeyExtensiblePollKindDisclosed, - PollEditFormType.undisclosed : kMXMessageContentKeyExtensiblePollKindUndisclosed] + private static func pollDetailsTypeToKindKey(_ type: EditFormPollType) -> String { + let mapping = [EditFormPollType.disclosed : kMXMessageContentKeyExtensiblePollKindDisclosed, + EditFormPollType.undisclosed : kMXMessageContentKeyExtensiblePollKindUndisclosed] return mapping[type] ?? kMXMessageContentKeyExtensiblePollKindDisclosed } - private static func pollKindKeyToDetailsType(_ key: String) -> PollEditFormType { - let mapping = [kMXMessageContentKeyExtensiblePollKindDisclosed : PollEditFormType.disclosed, - kMXMessageContentKeyExtensiblePollKindUndisclosed : PollEditFormType.undisclosed] + private static func pollKindKeyToDetailsType(_ key: String) -> EditFormPollType { + let mapping = [kMXMessageContentKeyExtensiblePollKindDisclosed : EditFormPollType.disclosed, + kMXMessageContentKeyExtensiblePollKindUndisclosed : EditFormPollType.undisclosed] - return mapping[key] ?? PollEditFormType.disclosed + return mapping[key] ?? EditFormPollType.disclosed } } diff --git a/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormModels.swift b/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormModels.swift index db08276ec..f8929bc38 100644 --- a/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormModels.swift +++ b/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormModels.swift @@ -17,11 +17,20 @@ import Foundation import SwiftUI -struct PollDetails { - let type: PollEditFormType +enum EditFormPollType { + case disclosed + case undisclosed +} + +struct EditFormPollDetails { + let type: EditFormPollType let question: String let answerOptions: [String] let maxSelections: UInt = 1 + + static var `default`: EditFormPollDetails { + EditFormPollDetails(type: .disclosed, question: "", answerOptions: ["", ""]) + } } enum PollEditFormMode { @@ -45,13 +54,8 @@ enum PollEditFormViewAction { enum PollEditFormViewModelResult { case cancel - case create(PollDetails) - case update(PollDetails) -} - -enum PollEditFormType { - case disclosed - case undisclosed + case create(EditFormPollDetails) + case update(EditFormPollDetails) } struct PollEditFormQuestion { @@ -96,7 +100,7 @@ struct PollEditFormViewState: BindableState { struct PollEditFormViewStateBindings { var question: PollEditFormQuestion var answerOptions: [PollEditFormAnswerOption] - var type: PollEditFormType + var type: EditFormPollType var alertInfo: PollEditFormErrorAlertInfo? } diff --git a/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormScreenState.swift b/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormScreenState.swift index 53d2d75e2..8d6720340 100644 --- a/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormScreenState.swift +++ b/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormScreenState.swift @@ -26,10 +26,7 @@ enum MockPollEditFormScreenState: MockScreenState, CaseIterable { } var screenView: ([Any], AnyView) { - let viewModel = PollEditFormViewModel(parameters: PollEditFormViewModelParameters(mode: .creation, - pollDetails: PollDetails(type: .disclosed, - question: "", - answerOptions: ["", ""]))) + let viewModel = PollEditFormViewModel(parameters: PollEditFormViewModelParameters(mode: .creation, pollDetails: .default)) return ([viewModel], AnyView(PollEditForm(viewModel: viewModel.context))) } } diff --git a/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormViewModel.swift b/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormViewModel.swift index 9b87ce138..63761a53a 100644 --- a/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormViewModel.swift +++ b/RiotSwiftUI/Modules/Room/PollEditForm/PollEditFormViewModel.swift @@ -19,7 +19,7 @@ import Combine struct PollEditFormViewModelParameters { let mode: PollEditFormMode - let pollDetails: PollDetails + let pollDetails: EditFormPollDetails } @available(iOS 14, *) @@ -97,7 +97,7 @@ class PollEditFormViewModel: PollEditFormViewModelType { title: VectorL10n.pollEditFormPostFailureTitle, subtitle: VectorL10n.pollEditFormPostFailureSubtitle) case .failedUpdatingPoll: - state.bindings.alertInfo = PollEditFormErrorAlertInfo(id: .failedCreatingPoll, + state.bindings.alertInfo = PollEditFormErrorAlertInfo(id: .failedUpdatingPoll, title: VectorL10n.pollEditFormUpdateFailureTitle, subtitle: VectorL10n.pollEditFormUpdateFailureSubtitle) case .none: @@ -109,8 +109,8 @@ class PollEditFormViewModel: PollEditFormViewModelType { // MARK: - Private - private func buildPollDetails() -> PollDetails { - return PollDetails(type: state.bindings.type, + private func buildPollDetails() -> EditFormPollDetails { + return EditFormPollDetails(type: state.bindings.type, question: state.bindings.question.text.trimmingCharacters(in: .whitespacesAndNewlines), answerOptions: state.bindings.answerOptions.compactMap({ answerOption in let text = answerOption.text.trimmingCharacters(in: .whitespacesAndNewlines) diff --git a/RiotSwiftUI/Modules/Room/PollEditForm/Test/Unit/PollEditFormViewModelTests.swift b/RiotSwiftUI/Modules/Room/PollEditForm/Test/Unit/PollEditFormViewModelTests.swift index c62afc61f..662f12c1a 100644 --- a/RiotSwiftUI/Modules/Room/PollEditForm/Test/Unit/PollEditFormViewModelTests.swift +++ b/RiotSwiftUI/Modules/Room/PollEditForm/Test/Unit/PollEditFormViewModelTests.swift @@ -26,8 +26,7 @@ class PollEditFormViewModelTests: XCTestCase { var cancellables = Set() override func setUpWithError() throws { - viewModel = PollEditFormViewModel(parameters: PollEditFormViewModelParameters(mode: .creation, - pollDetails: PollDetails(type: .disclosed, question: "", answerOptions: ["", ""]))) + viewModel = PollEditFormViewModel(parameters: PollEditFormViewModelParameters(mode: .creation, pollDetails: .default)) context = viewModel.context } diff --git a/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditForm.swift b/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditForm.swift index 6bcb1e233..05a736b5d 100644 --- a/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditForm.swift +++ b/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditForm.swift @@ -35,7 +35,7 @@ struct PollEditForm: View { ScrollView { VStack(alignment: .leading, spacing: 32.0) { - PollEditFormTypeView(selectedType: $viewModel.type) + PollEditFormTypePicker(selectedType: $viewModel.type) VStack(alignment: .leading, spacing: 16.0) { Text(VectorL10n.pollEditFormPollQuestionOrTopic) diff --git a/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditFormAnswerOptionView.swift b/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditFormAnswerOptionView.swift index ab74d8685..e3de14987 100644 --- a/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditFormAnswerOptionView.swift +++ b/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditFormAnswerOptionView.swift @@ -39,9 +39,7 @@ struct PollEditFormAnswerOptionView: View { self.focused = edit }) .textFieldStyle(BorderedInputFieldStyle(theme: _theme, isEditing: focused)) - Button { - onDelete() - } label: { + Button(action: onDelete) { Image(uiImage:Asset.Images.pollDeleteOptionIcon.image) } .accessibilityIdentifier("Delete answer option") diff --git a/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditFormTypeView.swift b/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditFormTypePicker.swift similarity index 71% rename from RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditFormTypeView.swift rename to RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditFormTypePicker.swift index 2858f7a89..590587d83 100644 --- a/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditFormTypeView.swift +++ b/RiotSwiftUI/Modules/Room/PollEditForm/View/PollEditFormTypePicker.swift @@ -17,28 +17,28 @@ import SwiftUI @available(iOS 14.0, *) -struct PollEditFormTypeView: View { +struct PollEditFormTypePicker: View { @Environment(\.theme) private var theme: ThemeSwiftUI - @Binding var selectedType: PollEditFormType + @Binding var selectedType: EditFormPollType var body: some View { VStack(alignment: .leading, spacing: 16.0) { Text(VectorL10n.pollEditFormPollType) .font(theme.fonts.title3SB) .foregroundColor(theme.colors.primaryContent) - PollTypeViewButton(type: .disclosed, selectedType: $selectedType) - PollTypeViewButton(type: .undisclosed, selectedType: $selectedType) + PollEditFormTypeButton(type: .disclosed, selectedType: $selectedType) + PollEditFormTypeButton(type: .undisclosed, selectedType: $selectedType) } } } @available(iOS 14.0, *) -private struct PollTypeViewButton: View { +private struct PollEditFormTypeButton: View { @Environment(\.theme) private var theme: ThemeSwiftUI - var type: PollEditFormType - @Binding var selectedType: PollEditFormType + let type: EditFormPollType + @Binding var selectedType: EditFormPollType var body: some View { Button { @@ -46,11 +46,7 @@ private struct PollTypeViewButton: View { } label: { HStack(alignment: .top, spacing: 8.0) { - if type == selectedType { - Image(uiImage: Asset.Images.pollTypeCheckboxSelected.image) - } else { - Image(uiImage: Asset.Images.pollTypeCheckboxDefault.image) - } + Image(uiImage: selectionImage) VStack(alignment: .leading, spacing: 2) { Text(title) @@ -81,14 +77,22 @@ private struct PollTypeViewButton: View { return VectorL10n.pollEditFormPollTypeClosedDescription } } -} - -@available(iOS 14.0, *) -struct PollEditFormTypeView_Previews: PreviewProvider { - static var previews: some View { - VStack { - PollEditFormTypeView(selectedType: Binding.constant(.disclosed)) - PollEditFormTypeView(selectedType: Binding.constant(.undisclosed)) + + private var selectionImage: UIImage { + if type == selectedType { + return Asset.Images.pollTypeCheckboxSelected.image + } else { + return Asset.Images.pollTypeCheckboxDefault.image + } + } +} + +@available(iOS 14.0, *) +struct PollEditFormTypePicker_Previews: PreviewProvider { + static var previews: some View { + VStack { + PollEditFormTypePicker(selectedType: Binding.constant(.disclosed)) + PollEditFormTypePicker(selectedType: Binding.constant(.undisclosed)) } } } diff --git a/RiotSwiftUI/Modules/Room/TimelinePoll/Coordinator/TimelinePollCoordinator.swift b/RiotSwiftUI/Modules/Room/TimelinePoll/Coordinator/TimelinePollCoordinator.swift index 87a0db032..0851f71d2 100644 --- a/RiotSwiftUI/Modules/Room/TimelinePoll/Coordinator/TimelinePollCoordinator.swift +++ b/RiotSwiftUI/Modules/Room/TimelinePoll/Coordinator/TimelinePollCoordinator.swift @@ -52,7 +52,7 @@ final class TimelinePollCoordinator: Coordinator, Presentable, PollAggregatorDel try pollAggregator = PollAggregator(session: parameters.session, room: parameters.room, pollStartEventId: parameters.pollStartEvent.eventId) pollAggregator.delegate = self - viewModel = TimelinePollViewModel(timelinePoll: buildTimelinePollFrom(pollAggregator.poll)) + viewModel = TimelinePollViewModel(timelinePollDetails: buildTimelinePollFrom(pollAggregator.poll)) viewModel.callback = { [weak self] result in guard let self = self else { return } @@ -95,7 +95,7 @@ final class TimelinePollCoordinator: Coordinator, Presentable, PollAggregatorDel } func canEditPoll() -> Bool { - return (pollAggregator.poll.isClosed == false && pollAggregator.poll.totalAnswerCount == 0) + return pollAggregator.poll.isClosed == false && pollAggregator.poll.totalAnswerCount == 0 } func endPoll() { @@ -126,7 +126,7 @@ final class TimelinePollCoordinator: Coordinator, Presentable, PollAggregatorDel // PollProtocol is intentionally not available in the SwiftUI target as we don't want // to add the SDK as a dependency to it. We need to translate from one to the other on this level. - func buildTimelinePollFrom(_ poll: PollProtocol) -> TimelinePoll { + func buildTimelinePollFrom(_ poll: PollProtocol) -> TimelinePollDetails { let answerOptions = poll.answerOptions.map { pollAnswerOption in TimelinePollAnswerOption(id: pollAnswerOption.id, text: pollAnswerOption.text, @@ -135,7 +135,7 @@ final class TimelinePollCoordinator: Coordinator, Presentable, PollAggregatorDel selected: pollAnswerOption.isCurrentUserSelection) } - return TimelinePoll(question: poll.text, + return TimelinePollDetails(question: poll.text, answerOptions: answerOptions, closed: poll.isClosed, totalAnswerCount: poll.totalAnswerCount, diff --git a/RiotSwiftUI/Modules/Room/TimelinePoll/Test/Unit/TimelinePollViewModelTests.swift b/RiotSwiftUI/Modules/Room/TimelinePoll/Test/Unit/TimelinePollViewModelTests.swift index 8b580f2a6..3de360418 100644 --- a/RiotSwiftUI/Modules/Room/TimelinePoll/Test/Unit/TimelinePollViewModelTests.swift +++ b/RiotSwiftUI/Modules/Room/TimelinePoll/Test/Unit/TimelinePollViewModelTests.swift @@ -30,15 +30,15 @@ class TimelinePollViewModelTests: XCTestCase { TimelinePollAnswerOption(id: "2", text: "2", count: 1, winner: false, selected: false), TimelinePollAnswerOption(id: "3", text: "3", count: 1, winner: false, selected: false)] - let timelinePoll = TimelinePoll(question: "Question", - answerOptions: answerOptions, - closed: false, - totalAnswerCount: 3, - type: .disclosed, - maxAllowedSelections: 1, - hasBeenEdited: false) + let timelinePoll = TimelinePollDetails(question: "Question", + answerOptions: answerOptions, + closed: false, + totalAnswerCount: 3, + type: .disclosed, + maxAllowedSelections: 1, + hasBeenEdited: false) - viewModel = TimelinePollViewModel(timelinePoll: timelinePoll) + viewModel = TimelinePollViewModel(timelinePollDetails: timelinePoll) context = viewModel.context } diff --git a/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollModels.swift b/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollModels.swift index af33cf012..da8abd7eb 100644 --- a/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollModels.swift +++ b/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollModels.swift @@ -21,7 +21,7 @@ typealias TimelinePollViewModelCallback = ((TimelinePollViewModelResult) -> Void enum TimelinePollStateAction { case viewAction(TimelinePollViewAction, TimelinePollViewModelCallback?) - case updateWithPoll(TimelinePoll) + case updateWithPoll(TimelinePollDetails) case showAnsweringFailure case showClosingFailure } @@ -55,7 +55,7 @@ class TimelinePollAnswerOption: Identifiable { } } -class TimelinePoll { +class TimelinePollDetails { var question: String var answerOptions: [TimelinePollAnswerOption] var closed: Bool @@ -68,7 +68,8 @@ class TimelinePoll { closed: Bool, totalAnswerCount: UInt, type: TimelinePollType, - maxAllowedSelections: UInt, hasBeenEdited: Bool) { + maxAllowedSelections: UInt, + hasBeenEdited: Bool) { self.question = question self.answerOptions = answerOptions self.closed = closed @@ -81,10 +82,18 @@ class TimelinePoll { var hasCurrentUserVoted: Bool { answerOptions.filter { $0.selected == true}.count > 0 } + + var shouldDiscloseResults: Bool { + if closed { + return totalAnswerCount > 0 + } else { + return type == .disclosed && totalAnswerCount > 0 && hasCurrentUserVoted + } + } } struct TimelinePollViewState: BindableState { - var poll: TimelinePoll + var poll: TimelinePollDetails var bindings: TimelinePollViewStateBindings } diff --git a/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollScreenState.swift b/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollScreenState.swift index fd8dcbb83..3fe93f8b8 100644 --- a/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollScreenState.swift +++ b/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollScreenState.swift @@ -25,23 +25,23 @@ enum MockTimelinePollScreenState: MockScreenState, CaseIterable { case closedUndisclosed var screenType: Any.Type { - TimelinePoll.self + TimelinePollDetails.self } var screenView: ([Any], AnyView) { let answerOptions = [TimelinePollAnswerOption(id: "1", text: "First", count: 10, winner: false, selected: false), - TimelinePollAnswerOption(id: "2", text: "Second", count: 5, winner: false, selected: true), - TimelinePollAnswerOption(id: "3", text: "Third", count: 15, winner: true, selected: false)] + TimelinePollAnswerOption(id: "2", text: "Second", count: 5, winner: false, selected: true), + TimelinePollAnswerOption(id: "3", text: "Third", count: 15, winner: true, selected: false)] - let poll = TimelinePoll(question: "Question", - answerOptions: answerOptions, - closed: (self == .closedDisclosed || self == .closedUndisclosed ? true : false), - totalAnswerCount: 20, - type: (self == .closedDisclosed || self == .openDisclosed ? .disclosed : .undisclosed), - maxAllowedSelections: 1, - hasBeenEdited: false) + let poll = TimelinePollDetails(question: "Question", + answerOptions: answerOptions, + closed: (self == .closedDisclosed || self == .closedUndisclosed ? true : false), + totalAnswerCount: 20, + type: (self == .closedDisclosed || self == .openDisclosed ? .disclosed : .undisclosed), + maxAllowedSelections: 1, + hasBeenEdited: false) - let viewModel = TimelinePollViewModel(timelinePoll: poll) + let viewModel = TimelinePollViewModel(timelinePollDetails: poll) return ([viewModel], AnyView(TimelinePollView(viewModel: viewModel.context))) } diff --git a/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollViewModel.swift b/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollViewModel.swift index adbb110c4..f28c7185c 100644 --- a/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollViewModel.swift +++ b/RiotSwiftUI/Modules/Room/TimelinePoll/TimelinePollViewModel.swift @@ -34,8 +34,8 @@ class TimelinePollViewModel: TimelinePollViewModelType { // MARK: - Setup - init(timelinePoll: TimelinePoll) { - super.init(initialViewState: TimelinePollViewState(poll: timelinePoll, bindings: TimelinePollViewStateBindings())) + init(timelinePollDetails: TimelinePollDetails) { + super.init(initialViewState: TimelinePollViewState(poll: timelinePollDetails, bindings: TimelinePollViewStateBindings())) } // MARK: - Public diff --git a/RiotSwiftUI/Modules/Room/TimelinePoll/View/TimelinePollAnswerOptionButton.swift b/RiotSwiftUI/Modules/Room/TimelinePoll/View/TimelinePollAnswerOptionButton.swift index e67139c88..7cd02911d 100644 --- a/RiotSwiftUI/Modules/Room/TimelinePoll/View/TimelinePollAnswerOptionButton.swift +++ b/RiotSwiftUI/Modules/Room/TimelinePoll/View/TimelinePollAnswerOptionButton.swift @@ -25,7 +25,7 @@ struct TimelinePollAnswerOptionButton: View { @Environment(\.theme) private var theme: ThemeSwiftUI - let poll: TimelinePoll + let poll: TimelinePollDetails let answerOption: TimelinePollAnswerOption let action: () -> Void @@ -65,12 +65,12 @@ struct TimelinePollAnswerOptionButton: View { if poll.type == .disclosed || poll.closed { HStack { - ProgressView(value: Double(shouldDiscloseResults ? answerOption.count : 0), + ProgressView(value: Double(poll.shouldDiscloseResults ? answerOption.count : 0), total: Double(poll.totalAnswerCount)) .progressViewStyle(LinearProgressViewStyle()) .scaleEffect(x: 1.0, y: 1.2, anchor: .center) - if (shouldDiscloseResults) { + if (poll.shouldDiscloseResults) { Text(answerOption.count == 1 ? VectorL10n.pollTimelineOneVote : VectorL10n.pollTimelineVotesCount(Int(answerOption.count))) .font(theme.fonts.footnote) .foregroundColor(poll.closed && answerOption.winner ? theme.colors.accent : theme.colors.secondaryContent) @@ -95,14 +95,6 @@ struct TimelinePollAnswerOptionButton: View { return answerOption.selected ? theme.colors.accent : theme.colors.quarterlyContent } - - private var shouldDiscloseResults: Bool { - if poll.closed { - return poll.totalAnswerCount > 0 - } else { - return poll.type == .disclosed && poll.totalAnswerCount > 0 && poll.hasCurrentUserVoted - } - } } @available(iOS 14.0, *) @@ -149,8 +141,8 @@ struct TimelinePollAnswerOptionButton_Previews: PreviewProvider { } } - static func buildPoll(closed: Bool, type: TimelinePollType) -> TimelinePoll { - TimelinePoll(question: "", + static func buildPoll(closed: Bool, type: TimelinePollType) -> TimelinePollDetails { + TimelinePollDetails(question: "", answerOptions: [], closed: closed, totalAnswerCount: 100,