fix club link

improve duplicate management
multistore
Raz 1 year ago
parent 703ea16a3b
commit 79cd364a89
  1. 2
      PadelClub.xcodeproj/project.pbxproj
  2. 2
      PadelClub/Data/Club.swift
  3. 7
      PadelClub/Data/TeamRegistration.swift
  4. 6
      PadelClub/Views/Navigation/MainView.swift
  5. 72
      PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift

@ -1882,7 +1882,6 @@
); );
MARKETING_VERSION = 0.1; MARKETING_VERSION = 0.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-function-bodies=5 -Xfrontend -warn-long-expression-type-checking=20 -Xfrontend -warn-long-function-bodies=50";
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
@ -1920,7 +1919,6 @@
); );
MARKETING_VERSION = 0.1; MARKETING_VERSION = 0.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-function-bodies=5 -Xfrontend -warn-long-expression-type-checking=20 -Xfrontend -warn-long-function-bodies=50";
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;

@ -63,7 +63,7 @@ class Club : ModelObject, Storable, Hashable {
} }
func shareURL() -> URL? { func shareURL() -> URL? {
return URLs.main.url.appending(path: "?club=\(id)") return URL(string: URLs.main.url.appending(path: "?club=\(id)").absoluteString.removingPercentEncoding!)
} }
var customizedCourts: [Court] { var customizedCourts: [Court] {

@ -192,6 +192,13 @@ class TeamRegistration: ModelObject, Storable {
unsortedPlayers().anySatisfy({ $0.contains(searchField) }) || self.name?.localizedCaseInsensitiveContains(searchField) == true unsortedPlayers().anySatisfy({ $0.contains(searchField) }) || self.name?.localizedCaseInsensitiveContains(searchField) == true
} }
func containsExactlyPlayerLicenses(_ playerLicenses: [String?]) -> Bool {
let arrayOfIds : [String] = unsortedPlayers().compactMap({ $0.licenceId?.strippedLicense?.canonicalVersion })
let ids : Set<String> = Set<String>(arrayOfIds.sorted())
let searchedIds = Set<String>(playerLicenses.compactMap({ $0?.strippedLicense?.canonicalVersion }).sorted())
return ids.hashValue == searchedIds.hashValue
}
func includes(_ players: [PlayerRegistration]) -> Bool { func includes(_ players: [PlayerRegistration]) -> Bool {
players.allSatisfy { player in players.allSatisfy { player in
includes(player) includes(player)

@ -48,8 +48,12 @@ struct MainView: View {
dataStore.matches.filter({ $0.confirmed && $0.startDate != nil && $0.endDate == nil && $0.courtIndex != nil }) dataStore.matches.filter({ $0.confirmed && $0.startDate != nil && $0.endDate == nil && $0.courtIndex != nil })
} }
private func _isConnected() -> Bool {
Store.main.hasToken() && Store.main.userId != nil
}
var badgeText: Text? { var badgeText: Text? {
Store.main.userId == nil ? Text("!").font(.headline) : nil _isConnected() == false ? Text("!").font(.headline) : nil
} }
var body: some View { var body: some View {

@ -58,6 +58,7 @@ struct InscriptionManagerView: View {
@State private var unsortedTeamsWithoutWO: [TeamRegistration] = [] @State private var unsortedTeamsWithoutWO: [TeamRegistration] = []
@State private var unsortedPlayers: [PlayerRegistration] = [] @State private var unsortedPlayers: [PlayerRegistration] = []
@State private var teamPaste: URL? @State private var teamPaste: URL?
@State private var confirmDuplicate: Bool = false
var messageSentFailed: Binding<Bool> { var messageSentFailed: Binding<Bool> {
Binding { Binding {
@ -197,6 +198,21 @@ struct InscriptionManagerView: View {
} }
} }
.alert("Cette équipe existe déjà", isPresented: $confirmDuplicate) {
Button("Créer l'équipe quand même") {
_createTeam(checkDuplicates: false)
}
Button("Annuler", role: .cancel) {
pasteString = nil
editedTeam = nil
createdPlayers.removeAll()
createdPlayerIds.removeAll()
}
} message: {
Text("Cette équipe existe déjà dans votre liste d'inscription.")
}
.alert("Un problème est survenu", isPresented: messageSentFailed) { .alert("Un problème est survenu", isPresented: messageSentFailed) {
Button("OK") { Button("OK") {
} }
@ -362,7 +378,7 @@ struct InscriptionManagerView: View {
//_prioritizeClubMembersButton() //_prioritizeClubMembersButton()
Button("Bloquer une place") { Button("Bloquer une place") {
_createTeam() _createTeam(checkDuplicates: false)
} }
} }
Divider() Divider()
@ -848,7 +864,36 @@ struct InscriptionManagerView: View {
return currentSelection return currentSelection
} }
private func _createTeam() { private func _currentSelectionIds() -> [String?] {
var currentSelection = [String?]()
createdPlayerIds.compactMap { id in
fetchPlayers.first(where: { id == $0.license })
}.forEach { player in
currentSelection.append(player.license)
}
createdPlayerIds.compactMap { id in
createdPlayers.first(where: { id == $0.id })
}.forEach {
currentSelection.append($0.licenceId)
}
return currentSelection
}
private func _isDuplicate() -> Bool {
let ids : [String?] = _currentSelectionIds()
if unfilteredTeams.anySatisfy({ $0.containsExactlyPlayerLicenses(ids) }) {
return true
}
return false
}
private func _createTeam(checkDuplicates: Bool) {
if checkDuplicates && _isDuplicate() {
confirmDuplicate = true
return
}
let players = _currentSelection() let players = _currentSelection()
let team = tournament.addTeam(players) let team = tournament.addTeam(players)
do { do {
@ -870,8 +915,13 @@ struct InscriptionManagerView: View {
_getTeams() _getTeams()
} }
private func _updateTeam() { private func _updateTeam(checkDuplicates: Bool) {
guard let editedTeam else { return } guard let editedTeam else { return }
if checkDuplicates && _isDuplicate() {
confirmDuplicate = true
return
}
let players = _currentSelection() let players = _currentSelection()
editedTeam.updatePlayers(players, inTournamentCategory: tournament.tournamentCategory) editedTeam.updatePlayers(players, inTournamentCategory: tournament.tournamentCategory)
do { do {
@ -915,27 +965,37 @@ struct InscriptionManagerView: View {
Section { Section {
ForEach(createdPlayerIds.sorted(), id: \.self) { id in ForEach(createdPlayerIds.sorted(), id: \.self) { id in
if let p = createdPlayers.first(where: { $0.id == id }) { if let p = createdPlayers.first(where: { $0.id == id }) {
VStack(alignment: .leading, spacing: 0) {
if unsortedPlayers.first(where: { $0.licenceId == p.licenceId }) != nil {
Text("Déjà inscrit !").foregroundStyle(.logoRed).bold()
}
PlayerView(player: p).tag(p.id) PlayerView(player: p).tag(p.id)
} }
}
if let p = fetchPlayers.first(where: { $0.license == id }) { if let p = fetchPlayers.first(where: { $0.license == id }) {
VStack(alignment: .leading, spacing: 0) {
if unsortedPlayers.first(where: { $0.licenceId == p.license }) != nil {
Text("Déjà inscrit !").foregroundStyle(.logoRed).bold()
}
ImportedPlayerView(player: p).tag(p.license!) ImportedPlayerView(player: p).tag(p.license!)
} }
} }
} }
}
if editedTeam == nil { if editedTeam == nil {
if createdPlayerIds.isEmpty { if createdPlayerIds.isEmpty {
RowButtonView("Bloquer une place") { RowButtonView("Bloquer une place") {
_createTeam() _createTeam(checkDuplicates: false)
} }
} else { } else {
RowButtonView("Ajouter l'équipe") { RowButtonView("Ajouter l'équipe") {
_createTeam() _createTeam(checkDuplicates: true)
} }
} }
} else { } else {
RowButtonView("Modifier l'équipe") { RowButtonView("Modifier l'équipe") {
_updateTeam() _updateTeam(checkDuplicates: true)
} }
} }

Loading…
Cancel
Save