Lien entre Login et Profil #16

Merged
leni.beaulaton merged 1 commits from lienLoginProfil into master 2 months ago

@ -20,7 +20,9 @@ sealed class Destination(val route: String) {
data object Login : Destination("Login")
data object Accueil : Destination("Accueil")
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 Quote : Destination("Quote")
data object Search : Destination("Search")
@ -36,12 +38,18 @@ fun AppNavigator() {
composable(Destination.Login.route) {
LoginPage(
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.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.Quote.route) { QuotePage() }
composable(Destination.Search.route) { SearchPage() }
@ -49,3 +57,4 @@ fun AppNavigator() {
composable(Destination.SubmitQuote.route) { SubmitQuotePage() }
}
}

@ -1,5 +1,6 @@
package com.example.what_the_fantasy.ui.screens
import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
@ -45,7 +46,7 @@ import com.example.what_the_fantasy.ui.theme.gradienBox
import java.security.MessageDigest
@Composable
fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: () -> Unit) {
fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Unit) {
val users = UserStub.allUsers;
@ -126,7 +127,7 @@ fun PassWdTextField(textpasswdResId : Int) : String{
@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)
Button(
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){
users.forEach { user ->
fun validLogin(identifiant : String, passwd : String, users : List<User>, navController: (Int) -> Unit){
users.forEachIndexed { index, user ->
val hashPassWd = hashPassword(passwd)
if (user.username == identifiant && user.password == hashPassWd) run {
navController()
if (user.username == identifiant && user.password == hashPassWd) {
// Utilise l'index pour naviguer à la position correspondante
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
@Composable
fun ProfilPage(navController: NavController) {
fun ProfilPage(index: Int, navController: NavController) {
val gradient = Brush.linearGradient(
colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), // Violet clair → Violet foncé
start = Offset(0f, 1000f), // Départ en bas à gauche
end = Offset(1000f, 0f) // Fin en haut à droite
)
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(
modifier = Modifier
@ -121,9 +121,6 @@ fun ProfilPage(navController: NavController) {
}
@Composable
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
fun EditEmail(userEmail: String) {
var email by remember { mutableStateOf(userEmail) }

Loading…
Cancel
Save