Page favoris

pull/45/head
Maxime ROCHER 2 months ago
parent 8fea813004
commit d384dc7f9e

@ -1,6 +1,7 @@
package com.example.what_the_fantasy.data.local package com.example.what_the_fantasy.data.local
import com.example.what_the_fantasy.data.model.Favorite import com.example.what_the_fantasy.data.model.Favorite
import com.example.what_the_fantasy.data.model.Quote
object FavoriteStub { object FavoriteStub {
val favorites: MutableList<Favorite> = mutableListOf( val favorites: MutableList<Favorite> = mutableListOf(
@ -16,4 +17,11 @@ object FavoriteStub {
Favorite(UserStub.users[9], QuoteStub.quote20), Favorite(UserStub.users[9], QuoteStub.quote20),
Favorite(UserStub.users[10], QuoteStub.quote11) Favorite(UserStub.users[10], QuoteStub.quote11)
) )
fun getFavoritesByUser(userId: Int): List<Quote> {
return favorites
.filter { it.user.id == userId }
.map { it.quote }
}
} }

@ -1,6 +1,12 @@
package com.example.what_the_fantasy.ui.navigations package com.example.what_the_fantasy.ui.navigations
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
@ -16,6 +22,7 @@ import com.example.what_the_fantasy.ui.screens.QuotePage
import com.example.what_the_fantasy.ui.screens.SearchPage import com.example.what_the_fantasy.ui.screens.SearchPage
import com.example.what_the_fantasy.ui.screens.SignUpPage import com.example.what_the_fantasy.ui.screens.SignUpPage
import com.example.what_the_fantasy.ui.screens.SubmitQuotePage import com.example.what_the_fantasy.ui.screens.SubmitQuotePage
import com.example.what_the_fantasy.ui.theme.colorNavBar
sealed class Destination(val route: String) { sealed class Destination(val route: String) {
@ -40,7 +47,6 @@ sealed class Destination(val route: String) {
} }
data object Quiz : Destination("Quiz") data object Quiz : Destination("Quiz")
data object QuizEnd : Destination("QuizEnd/{idQuiz}/{pts}") { data object QuizEnd : Destination("QuizEnd/{idQuiz}/{pts}") {
// Ajout paramètres idQuiz et pts
fun createIdAndPts(idQuiz : Int, pts : Int) = "QuizEnd/$idQuiz/$pts" fun createIdAndPts(idQuiz : Int, pts : Int) = "QuizEnd/$idQuiz/$pts"
} }
} }
@ -49,6 +55,12 @@ sealed class Destination(val route: String) {
fun AppNavigator() { fun AppNavigator() {
val navController = rememberNavController() val navController = rememberNavController()
val services = ServicesStub() val services = ServicesStub()
Scaffold(
modifier = Modifier.fillMaxSize(),
containerColor = colorNavBar
) { paddingValues ->
Box(modifier = Modifier.padding(paddingValues)) {
NavHost(navController, startDestination = Destination.Login.route) { NavHost(navController, startDestination = Destination.Login.route) {
composable(Destination.Login.route) { composable(Destination.Login.route) {
LoginPage( LoginPage(
@ -57,7 +69,6 @@ fun AppNavigator() {
}, },
navControllerProfil = { userIndex -> navControllerProfil = { userIndex ->
navController.navigate(Destination.Profil.createRoute(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 } popUpTo(Destination.Login.route) { inclusive = true }
} }
}, },
@ -90,32 +101,32 @@ fun AppNavigator() {
FavoritePage( FavoritePage(
index = userIndex, index = userIndex,
navAccueil = { userIndex -> navAccueil = { userIndex ->
navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.Accueil.createRoute(userIndex))
}, },
navQuiz = { userIndex -> navQuiz = { userIndex ->
navController.navigate(Destination.QuizMenu.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.QuizMenu.createRoute(userIndex))
}, },
navProfil = { userIndex -> navProfil = { userIndex ->
navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.Profil.createRoute(userIndex))
},
services
)
} }
) }
composable(Destination.Profil.route) { composable(Destination.Profil.route) {
// Récupère l'index passé dans la route
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
ProfilPage( ProfilPage(
index = userIndex, index = userIndex,
navFavorite = { userIndex -> navFavorite = { userIndex ->
navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.Favorite.createRoute(userIndex))
}, },
navAccueil = { userIndex -> navAccueil = { userIndex ->
navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.Accueil.createRoute(userIndex))
}, },
navQuiz = { userIndex -> navQuiz = { userIndex ->
navController.navigate(Destination.QuizMenu.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.QuizMenu.createRoute(userIndex))
}, },
navUnLog = { navUnLog = {
navController.navigate(Destination.Login.route) { navController.navigate(Destination.Login.route) {
// Vider pile de navigation pour empêcher le retour à la page profil
popUpTo(Destination.Profil.route) { inclusive = true } popUpTo(Destination.Profil.route) { inclusive = true }
} }
}, },
@ -124,28 +135,30 @@ 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( composable(Destination.SignUp.route) {
SignUpPage(
navControllerLogin = { navControllerLogin = {
navController.navigate(Destination.Login.route) { navController.navigate(Destination.Login.route) {
// Vider pile de navigation pour empêcher le retour à la page Sign up
popUpTo(Destination.Login.route) { inclusive = true } popUpTo(Destination.Login.route) { inclusive = true }
} }
},services) } },
services
)
}
composable(Destination.SubmitQuote.route) { SubmitQuotePage() } composable(Destination.SubmitQuote.route) { SubmitQuotePage() }
composable(Destination.QuizMenu.route) { composable(Destination.QuizMenu.route) {
val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1
QuizMenu( QuizMenu(
index = userIndex, index = userIndex,
navAccueil = { userIndex -> navAccueil = { userIndex ->
navController.navigate(Destination.Accueil.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.Accueil.createRoute(userIndex))
}, },
navFavorite = { userIndex -> navFavorite = { userIndex ->
navController.navigate(Destination.Favorite.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.Favorite.createRoute(userIndex))
}, },
navControllerQuiz = { navController.navigate(Destination.Quiz.route) }, navControllerQuiz = { navController.navigate(Destination.Quiz.route) },
navProfil = { userIndex -> navProfil = { userIndex ->
navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil navController.navigate(Destination.Profil.createRoute(userIndex))
} }
) )
} }
@ -168,3 +181,5 @@ fun AppNavigator() {
} }
} }
} }
}
}

@ -1,17 +1,25 @@
package com.example.what_the_fantasy.ui.screens package com.example.what_the_fantasy.ui.screens
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import com.example.what_the_fantasy.data.local.DailyQuoteStub
import com.example.what_the_fantasy.data.local.FavoriteStub
import com.example.what_the_fantasy.data.local.QuoteStub
import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.data.services.IServices
import com.example.what_the_fantasy.ui.components.NavBar import com.example.what_the_fantasy.ui.components.NavBar
import com.example.what_the_fantasy.ui.components.QuoteLittle
import com.example.what_the_fantasy.ui.theme.colorBackground import com.example.what_the_fantasy.ui.theme.colorBackground
@Composable @Composable
@ -19,8 +27,12 @@ fun FavoritePage(
index: Int, index: Int,
navAccueil: (Int) -> Unit, navAccueil: (Int) -> Unit,
navQuiz: (Int) -> Unit, navQuiz: (Int) -> Unit,
navProfil:(Int) -> Unit navProfil:(Int) -> Unit,
services: IServices
) { ) {
val user = services.getUserById(index) ?: return
val quotes = FavoriteStub.getFavoritesByUser(user.id)
NavBar(onFavorite = true, NavBar(onFavorite = true,
index = index, index = index,
navControllerFavorite = { }, navControllerFavorite = { },
@ -32,9 +44,24 @@ fun FavoritePage(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.background(colorBackground), .background(colorBackground),
contentAlignment = Alignment.Center contentAlignment = Alignment.TopCenter
){ ){
LazyColumn {
item{
Text(
text = "▶ Favoris ◀",
color = Color.White,
fontSize = 24.sp,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
textAlign = TextAlign.Center
)
}
items(quotes) { quote ->
QuoteLittle(quote)
}
}
} }
} }
} }
Loading…
Cancel
Save