Modification de la navigation

pull/32/head
Leni BEAULATON 2 months ago
parent 54d3102b93
commit 1715270d13

@ -50,13 +50,20 @@ fun AppNavigator() {
val navController = rememberNavController() val navController = rememberNavController()
val services = ServicesStub() val services = ServicesStub()
NavHost(navController, startDestination = Destination.Login.route) { NavHost(navController, startDestination = Destination.Login.route) {
composable(Destination.Login.route) { LoginPage( composable(Destination.Login.route) {
navControllerSignUp = { navController.navigate(Destination.SignUp.route) }, LoginPage(
navControllerProfil = { userIndex -> navControllerSignUp = {
navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.SignUp.route)
}, },
services navControllerProfil = { userIndex ->
) } navController.navigate(Destination.Profil.createRoute(userIndex)) {
// Vider pile de navigation pour empêcher le retour à la page Login
popUpTo(Destination.Login.route) { inclusive = true }
}
},
services
)
}
composable(Destination.Accueil.route) { composable(Destination.Accueil.route) {
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
AccueilPage( AccueilPage(
@ -104,7 +111,13 @@ fun AppNavigator() {
} }
composable(Destination.Quote.route) { QuotePage() } composable(Destination.Quote.route) { QuotePage() }
composable(Destination.Search.route) { SearchPage() } composable(Destination.Search.route) { SearchPage() }
composable(Destination.SignUp.route) { SignUpPage(navController, services) } composable(Destination.SignUp.route) { SignUpPage(
navControllerLogin = {
navController.navigate(Destination.Login.route){
// Vider pile de navigation pour empêcher le retour à la page Sign up
popUpTo(Destination.Login.route) { inclusive = true }
}
},services) }
composable(Destination.SubmitQuote.route) { SubmitQuotePage() } composable(Destination.SubmitQuote.route) { SubmitQuotePage() }
composable(Destination.QuizMenu.route) { composable(Destination.QuizMenu.route) {

@ -51,15 +51,15 @@ import com.example.what_the_fantasy.ui.theme.colorBackground
import com.example.what_the_fantasy.ui.theme.gradienBox import com.example.what_the_fantasy.ui.theme.gradienBox
import com.example.what_the_fantasy.data.services.ServicesStub import com.example.what_the_fantasy.data.services.ServicesStub
import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent
import com.example.what_the_fantasy.ui.components.hashPassword
@Composable @Composable
fun SignUpPage(navController: NavController, services : IServices) { fun SignUpPage(navControllerLogin: () -> Unit, services : IServices) {
var username by remember { mutableStateOf("") } var username by remember { mutableStateOf("") }
var email by remember { mutableStateOf("") } var email by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") } var password by remember { mutableStateOf("") }
var confirmPassword by remember { mutableStateOf("") } var confirmPassword by remember { mutableStateOf("") }
var passwordVisible by remember { mutableStateOf(false) } var passwordVisible by remember { mutableStateOf(false) }
//val servicesStub = ServicesStub()
Box( Box(
modifier = Modifier modifier = Modifier
@ -83,9 +83,9 @@ fun SignUpPage(navController: NavController, services : IServices) {
PassWdTextFieldSign(R.string.PasswdLogin,password, onValueChange = { password = it },passwordVisible,onPasswordVisibilityChange = { passwordVisible = !passwordVisible }) PassWdTextFieldSign(R.string.PasswdLogin,password, onValueChange = { password = it },passwordVisible,onPasswordVisibilityChange = { passwordVisible = !passwordVisible })
PassWdConfirmTextFieldSign(R.string.ConfirmPassWdSignUp,confirmPassword,onValueChange = { confirmPassword = it },passwordVisible,onPasswordVisibilityChange = { passwordVisible = !passwordVisible }) PassWdConfirmTextFieldSign(R.string.ConfirmPassWdSignUp,confirmPassword,onValueChange = { confirmPassword = it },passwordVisible,onPasswordVisibilityChange = { passwordVisible = !passwordVisible })
SpaceHeightComponent(16) SpaceHeightComponent(16)
ConnexionButtonSign(R.string.ButtonSignUp,18, Color.White, Color.Black, username, email, password, confirmPassword, services, navController = navController) ConnexionButtonSign(R.string.ButtonSignUp,18, Color.White, Color.Black, username, email, password, confirmPassword, services, navControllerLogin)
SpaceHeightComponent(16) SpaceHeightComponent(16)
ReturnLogin(R.string.ButtonLogin,12, Color.White, navController = navController) ReturnLogin(R.string.ButtonLogin,12, Color.White, navController = navControllerLogin)
} }
} }
@ -198,25 +198,28 @@ fun ConnexionButtonSign(
password: String, password: String,
confirmPassword: String, confirmPassword: String,
service: IServices, service: IServices,
navController: NavController navController: ()-> Unit
) { ) {
val title = stringResource(id = titleResId) val title = stringResource(id = titleResId)
var emailError by remember { mutableStateOf(false) } var emailError by remember { mutableStateOf(false) }
var passwordError by remember { mutableStateOf(false) } var passwordError by remember { mutableStateOf(false) }
var passwordErrorEmpty by remember { mutableStateOf(false) }
var usernameErrorEmpty by remember { mutableStateOf(false) } var usernameErrorEmpty by remember { mutableStateOf(false) }
var usernameErrorExist by remember { mutableStateOf(false) } var usernameErrorExist by remember { mutableStateOf(false) }
Button( Button(
onClick = { onClick = {
emailError = !isValidEmail(email) emailError = !isValidEmail(email)
passwordError = !arePasswordsMatching(password, confirmPassword) passwordError = !arePasswordsMatching(password, confirmPassword)
usernameErrorEmpty = username.isBlank() usernameErrorEmpty = username.isBlank()
passwordErrorEmpty = password.isBlank() || confirmPassword.isBlank()
if (!emailError && !passwordError && !usernameErrorEmpty) { if (!emailError && !passwordError && !usernameErrorEmpty && !passwordErrorEmpty) {
usernameErrorExist = !service.CreateUser(username, email, password, "https://img.freepik.com/vecteurs-libre/personnage-magicien-malefique-fantaisie_1045-193.jpg?size=338&ext=jpg", service) usernameErrorExist = !service.CreateUser(username, email, password, "https://img.freepik.com/vecteurs-libre/personnage-magicien-malefique-fantaisie_1045-193.jpg?size=338&ext=jpg", service)
if(!usernameErrorExist){
navController() // retour à la page login
}
} }
}, },
colors = ButtonDefaults.buttonColors(containerColor = colorButton), colors = ButtonDefaults.buttonColors(containerColor = colorButton),
@ -242,19 +245,26 @@ fun ConnexionButtonSign(
ErrorMessageProfileComponent(R.string.ErrorPasswordSignUp) ErrorMessageProfileComponent(R.string.ErrorPasswordSignUp)
} }
if (passwordErrorEmpty) {
ErrorMessageProfileComponent(R.string.ErrorPasswordEmpty)
}
} }
@Composable @Composable
fun ReturnLogin(titleResId: Int, size: Int, color: Color, navController: NavController) { fun ReturnLogin(titleResId: Int, size: Int, color: Color, navController: () -> Unit) {
val title = stringResource(id = titleResId) val title = stringResource(id = titleResId)
Text( Text(
text = title, text = title,
fontSize = size.sp, fontSize = size.sp,
color = color, color = color,
modifier = Modifier.clickable { modifier = Modifier.clickable {
navController.popBackStack() // Revenir à la page précédente navController() // Revenir à la page login
} }
) )
} }

@ -22,6 +22,7 @@
<string name="ErrorPasswordSignUp">Les mots de passe ne correspondent pas</string> <string name="ErrorPasswordSignUp">Les mots de passe ne correspondent pas</string>
<string name="ErrorUserEmptySignUp">Le nom d\'utilisateur ne peut pas être vide</string> <string name="ErrorUserEmptySignUp">Le nom d\'utilisateur ne peut pas être vide</string>
<string name="ErrorUserExistSignUp">Le nom d\'utilisateur n\'est pas disponible</string> <string name="ErrorUserExistSignUp">Le nom d\'utilisateur n\'est pas disponible</string>
<string name="ErrorPasswordEmpty">Vous devez mettre un mot de passe</string>
//Page Profil //Page Profil
<string name="titleProfile">Profil</string> <string name="titleProfile">Profil</string>

@ -21,6 +21,7 @@
<string name="ErrorPasswordSignUp">Passwords do not match</string> <string name="ErrorPasswordSignUp">Passwords do not match</string>
<string name="ErrorUserEmptySignUp">Username cannot be empty</string> <string name="ErrorUserEmptySignUp">Username cannot be empty</string>
<string name="ErrorUserExistSignUp">Username is not available</string> <string name="ErrorUserExistSignUp">Username is not available</string>
<string name="ErrorPasswordEmpty">You must put a password</string>
//Page Profil //Page Profil
<string name="titleProfile">Profile</string> <string name="titleProfile">Profile</string>

Loading…
Cancel
Save