|
|
|
|
@ -12,6 +12,8 @@ import LeStorage |
|
|
|
|
struct UmpireView: View { |
|
|
|
|
@Environment(NavigationViewModel.self) private var navigation: NavigationViewModel |
|
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
|
@State private var presentSearchView: Bool = false |
|
|
|
|
|
|
|
|
|
var lastDataSource: String? { |
|
|
|
|
dataStore.appSettings.lastDataSource |
|
|
|
|
} |
|
|
|
|
@ -46,8 +48,7 @@ struct UmpireView: View { |
|
|
|
|
Label("Mon compte", systemImage: "person.circle.fill") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let user = dataStore.user |
|
|
|
|
let currentPlayerData = user.currentPlayerData() |
|
|
|
|
let currentPlayerData = dataStore.user.currentPlayerData() |
|
|
|
|
Section { |
|
|
|
|
if let currentPlayerData { |
|
|
|
|
NavigationLink { |
|
|
|
|
@ -56,25 +57,8 @@ struct UmpireView: View { |
|
|
|
|
ImportedPlayerView(player: currentPlayerData) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
NavigationLink { |
|
|
|
|
SelectablePlayerListView(allowSelection: 1, searchField: user.firstName + " " + user.lastName, playerSelectionAction: { players in |
|
|
|
|
if let player = players.first { |
|
|
|
|
user.licenceId = player.license |
|
|
|
|
if user.clubsObjects().contains(where: { $0.code == player.clubCode }) == false { |
|
|
|
|
let userClub = Club.findOrCreate(name: player.clubName!, code: player.clubCode) |
|
|
|
|
do { |
|
|
|
|
try dataStore.clubs.addOrUpdate(instance: userClub) |
|
|
|
|
user.setUserClub(userClub) |
|
|
|
|
try dataStore.userStorage.update() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.id(UUID()) |
|
|
|
|
} label: { |
|
|
|
|
Label("Ma fiche joueur", systemImage: "person.bust.circle.fill") |
|
|
|
|
RowButtonView("Ma fiche joueur", systemImage: "person.bust.circle.fill") { |
|
|
|
|
presentSearchView = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} header: { |
|
|
|
|
@ -82,11 +66,11 @@ struct UmpireView: View { |
|
|
|
|
Text("Ma fiche joueur") |
|
|
|
|
} |
|
|
|
|
} footer: { |
|
|
|
|
if user.licenceId == nil { |
|
|
|
|
if dataStore.user.licenceId == nil { |
|
|
|
|
Text("Si vous avez participé à un tournoi dans les 12 derniers mois, Padel Club peut vous retrouver.") |
|
|
|
|
} else { |
|
|
|
|
Button("supprimer", role: .destructive) { |
|
|
|
|
user.licenceId = nil |
|
|
|
|
dataStore.user.licenceId = nil |
|
|
|
|
do { |
|
|
|
|
try dataStore.userStorage.update() |
|
|
|
|
} catch { |
|
|
|
|
@ -141,19 +125,19 @@ struct UmpireView: View { |
|
|
|
|
// Section { |
|
|
|
|
// Text("Tenup ID") |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// Section { |
|
|
|
|
// Text("Tournois") |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// Section { |
|
|
|
|
// NavigationLink { |
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// } label: { |
|
|
|
|
// Text("Favori") |
|
|
|
|
// } |
|
|
|
|
// NavigationLink { |
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// } label: { |
|
|
|
|
// Text("Black list") |
|
|
|
|
// } |
|
|
|
|
@ -161,7 +145,7 @@ struct UmpireView: View { |
|
|
|
|
} |
|
|
|
|
.navigationTitle("Juge-Arbitre") |
|
|
|
|
.toolbar { |
|
|
|
|
#if DEBUG |
|
|
|
|
#if DEBUG |
|
|
|
|
ToolbarItem(placement: .topBarTrailing) { |
|
|
|
|
if Store.main.collectionsCanSynchronize { |
|
|
|
|
Image(systemName: "checkmark.icloud") |
|
|
|
|
@ -169,7 +153,27 @@ struct UmpireView: View { |
|
|
|
|
Image(systemName: "icloud.slash") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
.sheet(isPresented: $presentSearchView) { |
|
|
|
|
let user = dataStore.user |
|
|
|
|
NavigationStack { |
|
|
|
|
SelectablePlayerListView(allowSelection: 1, searchField: user.firstName + " " + user.lastName, playerSelectionAction: { players in |
|
|
|
|
if let player = players.first { |
|
|
|
|
user.licenceId = player.license |
|
|
|
|
if user.clubsObjects().contains(where: { $0.code == player.clubCode }) == false { |
|
|
|
|
let userClub = Club.findOrCreate(name: player.clubName!, code: player.clubCode) |
|
|
|
|
do { |
|
|
|
|
try dataStore.clubs.addOrUpdate(instance: userClub) |
|
|
|
|
user.setUserClub(userClub) |
|
|
|
|
try dataStore.userStorage.update() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|