|
|
|
|
@ -16,6 +16,7 @@ struct UmpireView: View { |
|
|
|
|
|
|
|
|
|
@State private var presentSearchView: Bool = false |
|
|
|
|
@State private var showSubscriptions: Bool = false |
|
|
|
|
@State private var isImporting: Bool = false |
|
|
|
|
|
|
|
|
|
// @State var isConnected: Bool = false |
|
|
|
|
|
|
|
|
|
@ -54,17 +55,25 @@ struct UmpireView: View { |
|
|
|
|
|
|
|
|
|
let currentPlayerData = dataStore.user.currentPlayerData() |
|
|
|
|
Section { |
|
|
|
|
if let currentPlayerData { |
|
|
|
|
//todo palmares |
|
|
|
|
ImportedPlayerView(player: currentPlayerData) |
|
|
|
|
// NavigationLink { |
|
|
|
|
// |
|
|
|
|
// } label: { |
|
|
|
|
// ImportedPlayerView(player: currentPlayerData) |
|
|
|
|
// } |
|
|
|
|
if isImporting { |
|
|
|
|
LabeledContent { |
|
|
|
|
ProgressView() |
|
|
|
|
} label: { |
|
|
|
|
Text("Importation de vos données") |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
RowButtonView("Ma fiche joueur", systemImage: "person.bust") { |
|
|
|
|
presentSearchView = true |
|
|
|
|
if let currentPlayerData { |
|
|
|
|
//todo palmares |
|
|
|
|
ImportedPlayerView(player: currentPlayerData) |
|
|
|
|
// NavigationLink { |
|
|
|
|
// |
|
|
|
|
// } label: { |
|
|
|
|
// ImportedPlayerView(player: currentPlayerData) |
|
|
|
|
// } |
|
|
|
|
} else { |
|
|
|
|
RowButtonView("Ma fiche joueur", systemImage: "person.bust") { |
|
|
|
|
presentSearchView = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} footer: { |
|
|
|
|
@ -166,29 +175,12 @@ struct UmpireView: View { |
|
|
|
|
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) |
|
|
|
|
if userClub.hasBeenCreated(by: StoreCenter.main.userId) { |
|
|
|
|
do { |
|
|
|
|
try dataStore.clubs.addOrUpdate(instance: userClub) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
user.setUserClub(userClub) |
|
|
|
|
Task { |
|
|
|
|
await _importUmpireData(fromPlayer: player) |
|
|
|
|
} |
|
|
|
|
self.dataStore.saveUser() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
.task { |
|
|
|
|
do { |
|
|
|
|
try await dataStore.clubs.loadDataFromServerIfAllowed() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.navigationDestination(for: UmpireScreen.self) { screen in |
|
|
|
|
switch screen { |
|
|
|
|
@ -199,6 +191,31 @@ struct UmpireView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _importUmpireData(fromPlayer player: ImportedPlayer) async { |
|
|
|
|
isImporting = true |
|
|
|
|
do { |
|
|
|
|
dataStore.clubs.reset() |
|
|
|
|
try await dataStore.clubs.loadDataFromServerIfAllowed() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
let user = dataStore.user |
|
|
|
|
user.licenceId = player.license |
|
|
|
|
if user.clubsObjects().contains(where: { $0.code == player.clubCode }) == false { |
|
|
|
|
let userClub = Club.findOrCreate(name: player.clubName!, code: player.clubCode) |
|
|
|
|
if userClub.hasBeenCreated(by: StoreCenter.main.userId) { |
|
|
|
|
do { |
|
|
|
|
try dataStore.clubs.addOrUpdate(instance: userClub) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
user.setUserClub(userClub) |
|
|
|
|
} |
|
|
|
|
self.dataStore.saveUser() |
|
|
|
|
isImporting = false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _isConnected() -> Bool { |
|
|
|
|
return dataStore.user.username.count > 0 && StoreCenter.main.hasToken() |
|
|
|
|
} |
|
|
|
|
|