From 021708c02f57468c70c49c051cb6bfac15b9649b Mon Sep 17 00:00:00 2001 From: Raz Date: Mon, 21 Oct 2024 08:12:04 +0200 Subject: [PATCH] fix player search in cashier --- PadelClub.xcodeproj/project.pbxproj | 4 ++-- PadelClub/Data/PlayerRegistration.swift | 17 ++++++++++++++++- PadelClub/Views/Cashier/CashierView.swift | 5 +---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index f524ebf..542e56d 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -3174,7 +3174,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 9; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -3219,7 +3219,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 9; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Data/PlayerRegistration.swift b/PadelClub/Data/PlayerRegistration.swift index 0047976..c0874bf 100644 --- a/PadelClub/Data/PlayerRegistration.swift +++ b/PadelClub/Data/PlayerRegistration.swift @@ -155,7 +155,22 @@ final class PlayerRegistration: ModelObject, Storable { } func contains(_ searchField: String) -> Bool { - firstName.canonicalVersion.localizedCaseInsensitiveContains(searchField.canonicalVersion) || lastName.canonicalVersion.localizedCaseInsensitiveContains(searchField.canonicalVersion) + let nameComponents = searchField.canonicalVersion.split(separator: " ") + + if nameComponents.count > 1 { + let pairs = nameComponents.pairs() + return pairs.contains(where: { + (firstName.canonicalVersion.localizedCaseInsensitiveContains(String($0)) && + lastName.canonicalVersion.localizedCaseInsensitiveContains(String($1))) || + (firstName.canonicalVersion.localizedCaseInsensitiveContains(String($1)) && + lastName.canonicalVersion.localizedCaseInsensitiveContains(String($0))) + }) + } else { + return nameComponents.contains { component in + firstName.canonicalVersion.localizedCaseInsensitiveContains(component) || + lastName.canonicalVersion.localizedCaseInsensitiveContains(component) + } + } } func isSameAs(_ player: PlayerRegistration) -> Bool { diff --git a/PadelClub/Views/Cashier/CashierView.swift b/PadelClub/Views/Cashier/CashierView.swift index 9189735..ef95e65 100644 --- a/PadelClub/Views/Cashier/CashierView.swift +++ b/PadelClub/Views/Cashier/CashierView.swift @@ -70,10 +70,7 @@ class CashierViewModel: ObservableObject { func _shouldDisplayPlayer(_ player: PlayerRegistration) -> Bool { if searchText.isEmpty == false { - sortOption.shouldDisplayPlayer(player) - && filterOption.shouldDisplayPlayer(player) - && presenceFilterOption.shouldDisplayPlayer(player) - && player.contains(searchText) + player.contains(searchText) } else { sortOption.shouldDisplayPlayer(player) && filterOption.shouldDisplayPlayer(player)