From b178c0cff9bd9d50c8c8b4788bc3a24d8d33f61b Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Wed, 8 Feb 2023 15:22:23 +0100 Subject: [PATCH] Refactor if/else in PollOptionRow --- .../ComposeContent/Poll/PollOptionRow.swift | 64 ++++++++----------- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Poll/PollOptionRow.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Poll/PollOptionRow.swift index 852c628bf..f10c094f4 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Poll/PollOptionRow.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Poll/PollOptionRow.swift @@ -57,44 +57,32 @@ public struct PollOptionRow: View { } } } else { - // beautiful! - if let moveUp { - if let moveDown { - if let removeOption { - field - .accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp) - .accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown) - .accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption) - } else { - field - .accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp) - .accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown) - } - } else { - if let removeOption { - field - .accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp) - .accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption) - } else { - field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp) - } - } - } else { - if let moveDown { - if let removeOption { - field - .accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown) - .accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption) - } else { - field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown) - } - } else { - if let removeOption { - field.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption) - } else { - field - } - } + switch (moveUp, moveDown, removeOption) { + case let (.some(up), .some(down), .some(remove)): + field + .accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up) + .accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down) + .accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove) + case let (.some(up), .some(down), .none): + field + .accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up) + .accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down) + case let (.some(up), .none, .some(remove)): + field + .accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up) + .accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove) + case let (.some(up), .none, .none): + field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up) + case let (.none, .some(down), .some(remove)): + field + .accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down) + .accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove) + case let (.none, .some(down), .none): + field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down) + case let (.none, .none, .some(remove)): + field.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove) + case (.none, .none, .none): + field } } }