From 2bd79445c5fc83f472f3e0847046e450b1311384 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 5 Jun 2024 12:00:19 +0200 Subject: [PATCH] Fix issue with window creation --- .../Views/Navigation/Umpire/UmpireView.swift | 45 +++++-- PadelClub/Views/User/LoginView.swift | 21 ++- PadelClub/Views/User/MainUserView.swift | 1 + PadelClub/Views/User/UserCreationView.swift | 125 ++++++++---------- 4 files changed, 105 insertions(+), 87 deletions(-) diff --git a/PadelClub/Views/Navigation/Umpire/UmpireView.swift b/PadelClub/Views/Navigation/Umpire/UmpireView.swift index 1dd115e..236cd49 100644 --- a/PadelClub/Views/Navigation/Umpire/UmpireView.swift +++ b/PadelClub/Views/Navigation/Umpire/UmpireView.swift @@ -17,6 +17,8 @@ struct UmpireView: View { @State private var presentSearchView: Bool = false @State private var showSubscriptions: Bool = false +// @State var isConnected: Bool = false + var lastDataSource: String? { dataStore.appSettings.lastDataSource } @@ -47,18 +49,17 @@ struct UmpireView: View { } } - NavigationLink { - MainUserView() - } label: { - LabeledContent { - if Store.main.hasToken() { - Text(dataStore.user.username) - } else { - Image(systemName: "xmark.circle.fill") - .foregroundStyle(.logoRed) - } + if self._isConnected() { + NavigationLink { + AccountView(user: dataStore.user) { } } label: { - Label("Mon compte", systemImage: "person.fill") + AccountRowView(userName: dataStore.user.username) + } + } else { + NavigationLink { + LoginView {_ in } + } label: { + AccountRowView(userName: dataStore.user.username) } } @@ -211,6 +212,28 @@ struct UmpireView: View { } } } + + fileprivate func _isConnected() -> Bool { + return dataStore.user.username.count > 0 && Store.main.hasToken() + } + +} + +struct AccountRowView: View { + + var userName: String + var body: some View { + LabeledContent { + if Store.main.hasToken() { + Text(self.userName) + } else { + Image(systemName: "xmark.circle.fill") + .foregroundStyle(.logoRed) + } + } label: { + Label("Mon compte", systemImage: "person.fill") + } + } } #Preview { diff --git a/PadelClub/Views/User/LoginView.swift b/PadelClub/Views/User/LoginView.swift index b5092ee..2e4412b 100644 --- a/PadelClub/Views/User/LoginView.swift +++ b/PadelClub/Views/User/LoginView.swift @@ -18,11 +18,12 @@ struct LoginView: View { @State var isLoading: Bool = false @State var showEmailPopup: Bool = false + @State var showUserCreationForm: Bool = false + @State var showEmailValidationMessage: Bool = false + @State var showSubscriptionView: Bool = false @State var errorText: String? = nil - @State var showSubscriptionView: Bool = false - var loginFailed: Binding { Binding { errorText != nil @@ -32,8 +33,6 @@ struct LoginView: View { } } } - - var showEmailValidationMessage: Bool = false var handler: (User) -> () @@ -64,9 +63,19 @@ struct LoginView: View { if !self.showEmailValidationMessage { Section { - NavigationLink("Créer un compte") { - UserCreationView() + Button(action: { + self.showUserCreationForm = true + }, label: { + Text("Créer un compte") + }) + .sheet(isPresented: self.$showUserCreationForm) { + UserCreationFormView(isPresented: self.$showUserCreationForm, showEmailValidationMessage: self.$showEmailValidationMessage) } + + +// NavigationLink("Créer un compte") { +// UserCreationView() +// } Button(action: { self.showEmailPopup = true }, label: { diff --git a/PadelClub/Views/User/MainUserView.swift b/PadelClub/Views/User/MainUserView.swift index 2989aa1..20bbd2a 100644 --- a/PadelClub/Views/User/MainUserView.swift +++ b/PadelClub/Views/User/MainUserView.swift @@ -31,6 +31,7 @@ struct MainUserView: View { } fileprivate func _checkConnection() { + Logger.log("_checkConnection") self.isConnected = dataStore.user.username.count > 0 && Store.main.hasToken() } diff --git a/PadelClub/Views/User/UserCreationView.swift b/PadelClub/Views/User/UserCreationView.swift index 6571a5b..0dfdb7c 100644 --- a/PadelClub/Views/User/UserCreationView.swift +++ b/PadelClub/Views/User/UserCreationView.swift @@ -10,7 +10,8 @@ import LeStorage struct UserCreationFormView: View { - @Binding var showLoginScreen: Bool + @Binding var isPresented: Bool + @Binding var showEmailValidationMessage: Bool @State var username: String = "" @State var password1: String = "" @@ -39,56 +40,58 @@ struct UserCreationFormView: View { var body: some View { - Form { - - Section { - TextField("Nom d'utilisateur", text: self.$username) - .autocorrectionDisabled() - .textInputAutocapitalization(.never) - TextField("Email", text: self.$email) - .keyboardType(.emailAddress) - .textInputAutocapitalization(.never) - } - - Section { - SecureField("Mot de passe", text: self.$password1) - SecureField("Confirmez le mot de passe", text: self.$password2) - } - - Section { - TextField("Prénom", text: self.$firstName) - .autocorrectionDisabled() - TextField("Nom", text: self.$lastName) - .autocorrectionDisabled() - TextField("Téléphone", text: self.$phone) - .autocorrectionDisabled() - Picker("Pays", selection: $selectedCountryIndex) { - ForEach(0..