Refine polls UI in the timeline (#1474)

* Add summary view in PollRoomTimelineView

* Add selectedPollOption action

* Handle undisclosed polls

* Add more logics in PollRoomTimelineView

* Refine ended poll UI

* Refine poll layout

* More UI refinements

* Fix layout issue

* Refine progress bar

* Add poll mocks and UI tests

* Cleanup
This commit is contained in:
Alfonso Grillo
2023-08-11 12:25:16 +02:00
committed by GitHub
parent f64159670b
commit 25f66d2557
27 changed files with 465 additions and 144 deletions
@@ -212,6 +212,16 @@ enum RoomTimelineItemFixtures {
TextRoomTimelineItem(text: "Pork buffalo mollit culpa strip steak in leberkas flank cow.",
senderDisplayName: "Alice")]
}
static var disclosedPolls: [RoomTimelineItemProtocol] {
[PollRoomTimelineItem.mock(poll: .disclosed),
PollRoomTimelineItem.mock(poll: .endedDisclosed)]
}
static var undisclosedPolls: [RoomTimelineItemProtocol] {
[PollRoomTimelineItem.mock(poll: .undisclosed),
PollRoomTimelineItem.mock(poll: .endedUndisclosed)]
}
}
private extension TextRoomTimelineItem {
@@ -29,7 +29,7 @@ struct PollRoomTimelineItem: Equatable, EventBasedTimelineItemProtocol {
struct Poll: Equatable {
let question: String
let pollKind: Kind
let kind: Kind
let maxSelections: Int
let options: [Option]
let votes: [String: [String]]
@@ -46,5 +46,6 @@ struct Poll: Equatable {
let votes: Int
let allVotes: Int
let isSelected: Bool
let isWinning: Bool
}
}
@@ -333,16 +333,21 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
count + pair.value.count
}
let maxOptionVotes = votes.map(\.value.count).max()
let options = answers.map { answer in
Poll.Option(id: answer.id,
text: answer.text,
votes: votes[answer.id]?.count ?? 0,
allVotes: allVotes,
isSelected: votes[answer.id]?.contains(userID) ?? false)
let optionVotesCount = votes[answer.id]?.count
return Poll.Option(id: answer.id,
text: answer.text,
votes: optionVotesCount ?? 0,
allVotes: allVotes,
isSelected: votes[answer.id]?.contains(userID) ?? false,
isWinning: optionVotesCount.map { $0 == maxOptionVotes } ?? false)
}
let poll = Poll(question: question,
pollKind: .init(pollKind: pollKind),
kind: .init(pollKind: pollKind),
maxSelections: Int(maxSelections),
options: options,
votes: votes,