Merge pull request 'Lien entre Login et Profil' (#16) from lienLoginProfil into master

Reviewed-on: #16
pull/19/head
Leni BEAULATON 2 months ago
commit 2de8f5ef10

@ -20,7 +20,9 @@ sealed class Destination(val route: String) {
data object Login : Destination("Login") data object Login : Destination("Login")
data object Accueil : Destination("Accueil") data object Accueil : Destination("Accueil")
data object Favorite : Destination("Favorite") data object Favorite : Destination("Favorite")
data object Profil : Destination("Profil") data object Profil : Destination("Profil/{userIndex}") { // Ajout du paramètre userIndex
fun createRoute(userIndex: Int) = "Profil/$userIndex" // Fonction pour créer la route avec l'index
}
data object Quiz : Destination("Quiz") data object Quiz : Destination("Quiz")
data object Quote : Destination("Quote") data object Quote : Destination("Quote")
data object Search : Destination("Search") data object Search : Destination("Search")
@ -36,12 +38,18 @@ fun AppNavigator() {
composable(Destination.Login.route) { composable(Destination.Login.route) {
LoginPage( LoginPage(
navControllerSignUp = { navController.navigate(Destination.SignUp.route) }, navControllerSignUp = { navController.navigate(Destination.SignUp.route) },
navControllerProfil = { navController.navigate(Destination.Profil.route) } navControllerProfil = { userIndex ->
navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil
}
) )
} }
composable(Destination.Accueil.route) { AccueilPage() } composable(Destination.Accueil.route) { AccueilPage() }
composable(Destination.Favorite.route) { FavoritePage() } composable(Destination.Favorite.route) { FavoritePage() }
composable(Destination.Profil.route) { ProfilPage(navController) } composable(Destination.Profil.route) { backStackEntry ->
// Récupère l'index passé dans la route
val userIndex = backStackEntry.arguments?.getString("userIndex")?.toInt() ?: -1
ProfilPage(index = userIndex, navController = navController)
}
composable(Destination.Quiz.route) { QuizPage() } composable(Destination.Quiz.route) { QuizPage() }
composable(Destination.Quote.route) { QuotePage() } composable(Destination.Quote.route) { QuotePage() }
composable(Destination.Search.route) { SearchPage() } composable(Destination.Search.route) { SearchPage() }
@ -49,3 +57,4 @@ fun AppNavigator() {
composable(Destination.SubmitQuote.route) { SubmitQuotePage() } composable(Destination.SubmitQuote.route) { SubmitQuotePage() }
} }
} }

@ -1,5 +1,6 @@
package com.example.what_the_fantasy.ui.screens package com.example.what_the_fantasy.ui.screens
import android.util.Log
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
@ -45,7 +46,7 @@ import com.example.what_the_fantasy.ui.theme.gradienBox
import java.security.MessageDigest import java.security.MessageDigest
@Composable @Composable
fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: () -> Unit) { fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Unit) {
val users = UserStub.allUsers; val users = UserStub.allUsers;
@ -126,7 +127,7 @@ fun PassWdTextField(textpasswdResId : Int) : String{
@Composable @Composable
fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: () -> Unit){ fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: (Int) -> Unit){
val title = stringResource(id = titleResId) val title = stringResource(id = titleResId)
Button( Button(
onClick = { validLogin(id, passwd, userStub, navController) }, onClick = { validLogin(id, passwd, userStub, navController) },
@ -139,12 +140,12 @@ fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, ti
} }
fun validLogin(identifiant : String, passwd : String, users : List<User>, navController: () -> Unit){ fun validLogin(identifiant : String, passwd : String, users : List<User>, navController: (Int) -> Unit){
users.forEach { user -> users.forEachIndexed { index, user ->
val hashPassWd = hashPassword(passwd) val hashPassWd = hashPassword(passwd)
if (user.username == identifiant && user.password == hashPassWd) {
if (user.username == identifiant && user.password == hashPassWd) run { // Utilise l'index pour naviguer à la position correspondante
navController() navController(index) // Passer l'index à la fonction navController
} }
} }
} }

@ -67,14 +67,14 @@ import com.example.what_the_fantasy.ui.components.TitlePageComponent
import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme
@Composable @Composable
fun ProfilPage(navController: NavController) { fun ProfilPage(index: Int, navController: NavController) {
val gradient = Brush.linearGradient( val gradient = Brush.linearGradient(
colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), // Violet clair → Violet foncé colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), // Violet clair → Violet foncé
start = Offset(0f, 1000f), // Départ en bas à gauche start = Offset(0f, 1000f), // Départ en bas à gauche
end = Offset(1000f, 0f) // Fin en haut à droite end = Offset(1000f, 0f) // Fin en haut à droite
) )
val user = UserStub.allUsers val user = UserStub.allUsers
val index = 2 // Pour changer l'utilisateur pour le moment //val index = 2 // Pour changer l'utilisateur pour le moment
Box( Box(
modifier = Modifier modifier = Modifier
@ -121,9 +121,6 @@ fun ProfilPage(navController: NavController) {
} }
@Composable @Composable
fun ImageProfil(imgProfil : String, size :Int, sizeBorber : Int, colorBorder : Color){ fun ImageProfil(imgProfil : String, size :Int, sizeBorber : Int, colorBorder : Color){
@ -136,7 +133,6 @@ fun ImageProfil(imgProfil : String, size :Int, sizeBorber : Int, colorBorder : C
) )
} }
@Composable @Composable
fun EditEmail(userEmail: String) { fun EditEmail(userEmail: String) {
var email by remember { mutableStateOf(userEmail) } var email by remember { mutableStateOf(userEmail) }

Loading…
Cancel
Save