Refactor if/else in PollOptionRow

This commit is contained in:
Marcus Kida 2023-02-08 15:22:23 +01:00
parent 8217f5ce28
commit b178c0cff9
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
1 changed files with 26 additions and 38 deletions

View File

@ -57,47 +57,35 @@ public struct PollOptionRow: View {
} }
} }
} else { } else {
// beautiful! switch (moveUp, moveDown, removeOption) {
if let moveUp { case let (.some(up), .some(down), .some(remove)):
if let moveDown {
if let removeOption {
field field
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp) .accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up)
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown) .accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down)
.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption) .accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove)
} else { case let (.some(up), .some(down), .none):
field field
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp) .accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up)
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown) .accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down)
} case let (.some(up), .none, .some(remove)):
} else {
if let removeOption {
field field
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp) .accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up)
.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption) .accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove)
} else { case let (.some(up), .none, .none):
field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp) field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up)
} case let (.none, .some(down), .some(remove)):
}
} else {
if let moveDown {
if let removeOption {
field field
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown) .accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down)
.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption) .accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove)
} else { case let (.none, .some(down), .none):
field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown) field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down)
} case let (.none, .none, .some(remove)):
} else { field.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove)
if let removeOption { case (.none, .none, .none):
field.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption)
} else {
field field
} }
} }
} }
}
}
.background(Color(viewModel.backgroundColor)) .background(Color(viewModel.backgroundColor))
.cornerRadius(10) .cornerRadius(10)
.shadow(color: .black.opacity(0.3), radius: 2, x: 0, y: 1) .shadow(color: .black.opacity(0.3), radius: 2, x: 0, y: 1)