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. 78
      PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift

@ -1882,7 +1882,6 @@
);
MARKETING_VERSION = 0.1;
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_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
@ -1920,7 +1919,6 @@
);
MARKETING_VERSION = 0.1;
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_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;

@ -63,7 +63,7 @@ class Club : ModelObject, Storable, Hashable {
}
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] {

@ -191,6 +191,13 @@ class TeamRegistration: ModelObject, Storable {
func contains(_ searchField: String) -> Bool {
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 {
players.allSatisfy { player in

@ -48,8 +48,12 @@ struct MainView: View {
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? {
Store.main.userId == nil ? Text("!").font(.headline) : nil
_isConnected() == false ? Text("!").font(.headline) : nil
}
var body: some View {

@ -58,6 +58,7 @@ struct InscriptionManagerView: View {
@State private var unsortedTeamsWithoutWO: [TeamRegistration] = []
@State private var unsortedPlayers: [PlayerRegistration] = []
@State private var teamPaste: URL?
@State private var confirmDuplicate: Bool = false
var messageSentFailed: Binding<Bool> {
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) {
Button("OK") {
}
@ -362,7 +378,7 @@ struct InscriptionManagerView: View {
//_prioritizeClubMembersButton()
Button("Bloquer une place") {
_createTeam()
_createTeam(checkDuplicates: false)
}
}
Divider()
@ -829,7 +845,7 @@ struct InscriptionManagerView: View {
return predicate
}
private func _currentSelection() -> Set<PlayerRegistration> {
var currentSelection = Set<PlayerRegistration>()
createdPlayerIds.compactMap { id in
@ -847,8 +863,37 @@ struct InscriptionManagerView: View {
}
return currentSelection
}
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 _createTeam() {
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 team = tournament.addTeam(players)
do {
@ -870,8 +915,13 @@ struct InscriptionManagerView: View {
_getTeams()
}
private func _updateTeam() {
private func _updateTeam(checkDuplicates: Bool) {
guard let editedTeam else { return }
if checkDuplicates && _isDuplicate() {
confirmDuplicate = true
return
}
let players = _currentSelection()
editedTeam.updatePlayers(players, inTournamentCategory: tournament.tournamentCategory)
do {
@ -915,10 +965,20 @@ struct InscriptionManagerView: View {
Section {
ForEach(createdPlayerIds.sorted(), id: \.self) { id in
if let p = createdPlayers.first(where: { $0.id == id }) {
PlayerView(player: p).tag(p.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)
}
}
if let p = fetchPlayers.first(where: { $0.license == id }) {
ImportedPlayerView(player: p).tag(p.license!)
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!)
}
}
}
}
@ -926,16 +986,16 @@ struct InscriptionManagerView: View {
if editedTeam == nil {
if createdPlayerIds.isEmpty {
RowButtonView("Bloquer une place") {
_createTeam()
_createTeam(checkDuplicates: false)
}
} else {
RowButtonView("Ajouter l'équipe") {
_createTeam()
_createTeam(checkDuplicates: true)
}
}
} else {
RowButtonView("Modifier l'équipe") {
_updateTeam()
_updateTeam(checkDuplicates: true)
}
}

Loading…
Cancel
Save