mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Add max selections support for polls (#5726)
This commit is contained in:
committed by
GitHub
parent
173a927bf8
commit
30e4e6339d
+17
@@ -43,6 +43,23 @@ nonisolated struct Poll: Hashable {
|
||||
options.filter(\.isSelected).count == maxSelections
|
||||
}
|
||||
|
||||
func answerIDsAfterSelecting(optionID: String) -> [String]? {
|
||||
guard options.contains(where: { $0.id == optionID }) else { return nil }
|
||||
|
||||
let selectedOptionIDs = options.filter(\.isSelected).map(\.id)
|
||||
if selectedOptionIDs.contains(optionID) {
|
||||
guard maxSelections > 1, selectedOptionIDs.count > 1 else { return nil }
|
||||
return selectedOptionIDs.filter { $0 != optionID }
|
||||
}
|
||||
|
||||
guard maxSelections > 1 else {
|
||||
return [optionID]
|
||||
}
|
||||
|
||||
guard selectedOptionIDs.count < maxSelections else { return nil }
|
||||
return selectedOptionIDs + [optionID]
|
||||
}
|
||||
|
||||
struct Option: Hashable {
|
||||
let id: String
|
||||
let text: String
|
||||
|
||||
Reference in New Issue
Block a user