|
|
|
|
@ -22,6 +22,7 @@ let padelBeachImportTip = PadelBeachImportTip() |
|
|
|
|
struct InscriptionManagerView: View { |
|
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
|
@EnvironmentObject var networkMonitor: NetworkMonitor |
|
|
|
|
@Environment(\.dismiss) var dismiss |
|
|
|
|
|
|
|
|
|
@FetchRequest( |
|
|
|
|
sortDescriptors: [], |
|
|
|
|
@ -29,6 +30,8 @@ struct InscriptionManagerView: View { |
|
|
|
|
private var fetchPlayers: FetchedResults<ImportedPlayer> |
|
|
|
|
|
|
|
|
|
var tournament: Tournament |
|
|
|
|
var cancelShouldDismiss: Bool = false |
|
|
|
|
|
|
|
|
|
@State private var searchField: String = "" |
|
|
|
|
@State private var presentSearch: Bool = false |
|
|
|
|
@State private var presentPlayerSearch: Bool = false |
|
|
|
|
@ -101,20 +104,15 @@ struct InscriptionManagerView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let categoryOption: PlayerFilterOption |
|
|
|
|
let filterable: Bool |
|
|
|
|
|
|
|
|
|
init(tournament: Tournament) { |
|
|
|
|
init(tournament: Tournament, pasteString: String? = nil) { |
|
|
|
|
self.tournament = tournament |
|
|
|
|
_currentRankSourceDate = State(wrappedValue: tournament.rankSourceDate) |
|
|
|
|
switch tournament.tournamentCategory { |
|
|
|
|
case .women: |
|
|
|
|
categoryOption = .female |
|
|
|
|
filterable = false |
|
|
|
|
default: |
|
|
|
|
categoryOption = .all |
|
|
|
|
filterable = true |
|
|
|
|
if let pasteString { |
|
|
|
|
_pasteString = .init(wrappedValue: pasteString) |
|
|
|
|
_fetchPlayers = FetchRequest<ImportedPlayer>(sortDescriptors: [NSSortDescriptor(keyPath: \ImportedPlayer.rank, ascending: true)], predicate: Self._pastePredicate(pasteField: pasteString, mostRecentDate: tournament.rankSourceDate, filterOption: tournament.tournamentCategory.playerFilterOption)) |
|
|
|
|
_autoSelect = .init(wrappedValue: true) |
|
|
|
|
cancelShouldDismiss = true |
|
|
|
|
} |
|
|
|
|
_currentRankSourceDate = State(wrappedValue: tournament.rankSourceDate) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _clearScreen() { |
|
|
|
|
@ -337,6 +335,9 @@ struct InscriptionManagerView: View { |
|
|
|
|
editedTeam = nil |
|
|
|
|
createdPlayers.removeAll() |
|
|
|
|
createdPlayerIds.removeAll() |
|
|
|
|
if cancelShouldDismiss { |
|
|
|
|
dismiss() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
@ -515,7 +516,7 @@ struct InscriptionManagerView: View { |
|
|
|
|
RowButtonView("Créer une équipe") { |
|
|
|
|
Task { |
|
|
|
|
await MainActor.run() { |
|
|
|
|
fetchPlayers.nsPredicate = _pastePredicate(pasteField: searchField, mostRecentDate: SourceFileManager.shared.mostRecentDateAvailable) |
|
|
|
|
fetchPlayers.nsPredicate = Self._pastePredicate(pasteField: searchField, mostRecentDate: SourceFileManager.shared.mostRecentDateAvailable, filterOption: _filterOption()) |
|
|
|
|
fetchPlayers.nsSortDescriptors = [NSSortDescriptor(keyPath: \ImportedPlayer.rank, ascending: true)] |
|
|
|
|
pasteString = searchField |
|
|
|
|
} |
|
|
|
|
@ -572,7 +573,7 @@ struct InscriptionManagerView: View { |
|
|
|
|
guard let first = strings.first else { return } |
|
|
|
|
Task { |
|
|
|
|
await MainActor.run { |
|
|
|
|
fetchPlayers.nsPredicate = _pastePredicate(pasteField: first, mostRecentDate: SourceFileManager.shared.mostRecentDateAvailable) |
|
|
|
|
fetchPlayers.nsPredicate = Self._pastePredicate(pasteField: first, mostRecentDate: SourceFileManager.shared.mostRecentDateAvailable, filterOption: _filterOption()) |
|
|
|
|
fetchPlayers.nsSortDescriptors = [NSSortDescriptor(keyPath: \ImportedPlayer.rank, ascending: true)] |
|
|
|
|
pasteString = first |
|
|
|
|
autoSelect = true |
|
|
|
|
@ -641,14 +642,7 @@ struct InscriptionManagerView: View { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _filterOption() -> PlayerFilterOption { |
|
|
|
|
switch tournament.tournamentCategory { |
|
|
|
|
case .men: |
|
|
|
|
return .male |
|
|
|
|
case .women: |
|
|
|
|
return .female |
|
|
|
|
case .mix: |
|
|
|
|
return .all |
|
|
|
|
} |
|
|
|
|
return tournament.tournamentCategory.playerFilterOption |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ViewBuilder |
|
|
|
|
@ -672,7 +666,7 @@ struct InscriptionManagerView: View { |
|
|
|
|
if let paste = UIPasteboard.general.string { |
|
|
|
|
Task { |
|
|
|
|
await MainActor.run { |
|
|
|
|
fetchPlayers.nsPredicate = _pastePredicate(pasteField: paste, mostRecentDate: SourceFileManager.shared.mostRecentDateAvailable) |
|
|
|
|
fetchPlayers.nsPredicate = Self._pastePredicate(pasteField: paste, mostRecentDate: SourceFileManager.shared.mostRecentDateAvailable, filterOption: _filterOption()) |
|
|
|
|
fetchPlayers.nsSortDescriptors = [NSSortDescriptor(keyPath: \ImportedPlayer.rank, ascending: true)] |
|
|
|
|
pasteString = paste |
|
|
|
|
autoSelect = true |
|
|
|
|
@ -739,7 +733,7 @@ struct InscriptionManagerView: View { |
|
|
|
|
LabeledContent { |
|
|
|
|
Text(max(0, unsortedTeamsWithoutWO.count - tournament.teamCount).formatted()).font(.largeTitle) |
|
|
|
|
} label: { |
|
|
|
|
Text("Liste d'attente") |
|
|
|
|
Text("Attente") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
NavigationLink { |
|
|
|
|
@ -807,7 +801,7 @@ struct InscriptionManagerView: View { |
|
|
|
|
selectionSearchField ?? pasteString |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _pastePredicate(pasteField: String, mostRecentDate: Date?) -> NSPredicate? { |
|
|
|
|
static private func _pastePredicate(pasteField: String, mostRecentDate: Date?, filterOption: PlayerFilterOption) -> NSPredicate? { |
|
|
|
|
let text = pasteField.canonicalVersion |
|
|
|
|
|
|
|
|
|
let nameComponents = text.components(separatedBy: .whitespacesAndNewlines).compactMap { $0.isEmpty ? nil : $0 }.filter({ $0 != "de" && $0 != "la" && $0 != "le" && $0.count > 1 }) |
|
|
|
|
@ -816,9 +810,9 @@ struct InscriptionManagerView: View { |
|
|
|
|
//self.wordsCount = nameComponents.count |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _filterOption() == .male { |
|
|
|
|
if filterOption == .male { |
|
|
|
|
andPredicates.append(NSPredicate(format: "male == YES")) |
|
|
|
|
} else if _filterOption() == .female { |
|
|
|
|
} else if filterOption == .female { |
|
|
|
|
andPredicates.append(NSPredicate(format: "male == NO")) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1244,9 +1238,9 @@ struct InscriptionManagerView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#Preview { |
|
|
|
|
NavigationStack { |
|
|
|
|
InscriptionManagerView(tournament: Tournament.mock()) |
|
|
|
|
.environment(Tournament.mock()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//#Preview { |
|
|
|
|
// NavigationStack { |
|
|
|
|
// InscriptionManagerView(tournament: Tournament.mock()) |
|
|
|
|
// .environment(Tournament.mock()) |
|
|
|
|
// } |
|
|
|
|
//} |
|
|
|
|
|