|
@@ -40,30 +40,30 @@ import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
import androidx.navigation.NavHostController
|
|
|
import coil.compose.rememberImagePainter
|
|
|
-import com.example.lectionsupabase.R
|
|
|
import com.example.lectionsupabase.domain.utils.Constants
|
|
|
import com.example.lectionsupabase.model.Admin
|
|
|
import com.example.lectionsupabase.model.Cars
|
|
|
+import com.example.lectionsupabase.model.Restaurants
|
|
|
import io.github.jan.supabase.gotrue.auth
|
|
|
import io.github.jan.supabase.postgrest.from
|
|
|
|
|
|
@Composable
|
|
|
-fun CarsList(navHost: NavHostController) {
|
|
|
- var cars by remember { mutableStateOf<List<Cars>>(listOf()) }
|
|
|
- var loadingCars by remember { mutableStateOf(true) }
|
|
|
+fun Restaurants(navHost: NavHostController) {
|
|
|
+ var restaurants by remember { mutableStateOf<List<Restaurants>>(listOf()) }
|
|
|
+ var loadingRest by remember { mutableStateOf(true) }
|
|
|
var loadingUsers by remember { mutableStateOf(true) }
|
|
|
var users by remember { mutableStateOf<List<Admin>>(listOf()) }
|
|
|
|
|
|
// Загружаем список автомобилей
|
|
|
LaunchedEffect(Unit) {
|
|
|
try {
|
|
|
- cars = Constants.supabase.from("Cars")
|
|
|
+ restaurants = Constants.supabase.from("Restaurants")
|
|
|
.select()
|
|
|
- .decodeList<Cars>()
|
|
|
- loadingCars = false
|
|
|
+ .decodeList<Restaurants>()
|
|
|
+ loadingRest = false
|
|
|
} catch (e: Exception) {
|
|
|
println("Error loading cars: ${e.message}")
|
|
|
- loadingCars = false
|
|
|
+ loadingRest = false
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -95,24 +95,24 @@ fun CarsList(navHost: NavHostController) {
|
|
|
horizontalArrangement = Arrangement.SpaceBetween
|
|
|
) {
|
|
|
Text(
|
|
|
- text = "Модельный ряд Lexus",
|
|
|
+ text = "Рестораны",
|
|
|
style = MaterialTheme.typography.headlineMedium,
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
color = MaterialTheme.colorScheme.onBackground
|
|
|
)
|
|
|
IconButton(
|
|
|
- onClick = { navHost.navigate("DealersList") }
|
|
|
+ onClick = { navHost.navigate("Cinema") }
|
|
|
) {
|
|
|
Icon(
|
|
|
imageVector = Icons.Default.ArrowForward,
|
|
|
- contentDescription = "Перейти к дилерам",
|
|
|
+ contentDescription = "Перейти к киноафише",
|
|
|
tint = MaterialTheme.colorScheme.primary
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Загрузка автомобилей
|
|
|
- if (loadingCars) {
|
|
|
+ if (loadingRest) {
|
|
|
Box(
|
|
|
modifier = Modifier.fillMaxSize(),
|
|
|
contentAlignment = Alignment.Center
|
|
@@ -127,7 +127,7 @@ fun CarsList(navHost: NavHostController) {
|
|
|
.padding(bottom = 16.dp),
|
|
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
|
) {
|
|
|
- items(cars, key = { car -> car.id }) { car ->
|
|
|
+ items(restaurants, key = { restaurant -> restaurant.id }) { restaurant ->
|
|
|
Card(
|
|
|
modifier = Modifier
|
|
|
.fillMaxWidth()
|
|
@@ -138,14 +138,28 @@ fun CarsList(navHost: NavHostController) {
|
|
|
) {
|
|
|
Column(modifier = Modifier.fillMaxWidth()) {
|
|
|
Text(
|
|
|
- text = "${car.brand} ${car.model}",
|
|
|
+ text = "${restaurant.name}",
|
|
|
+ style = MaterialTheme.typography.titleMedium,
|
|
|
+ fontWeight = FontWeight.SemiBold,
|
|
|
+ fontSize = 18.sp,
|
|
|
+ modifier = Modifier.padding(16.dp)
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ text = "${restaurant.location}",
|
|
|
+ style = MaterialTheme.typography.titleMedium,
|
|
|
+ fontWeight = FontWeight.SemiBold,
|
|
|
+ fontSize = 18.sp,
|
|
|
+ modifier = Modifier.padding(16.dp)
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ text = "${restaurant.cuisin}",
|
|
|
style = MaterialTheme.typography.titleMedium,
|
|
|
fontWeight = FontWeight.SemiBold,
|
|
|
fontSize = 18.sp,
|
|
|
modifier = Modifier.padding(16.dp)
|
|
|
)
|
|
|
val painter = rememberImagePainter(
|
|
|
- data = car.image,
|
|
|
+ data = restaurant.picture,
|
|
|
builder = {
|
|
|
crossfade(true)
|
|
|
}
|
|
@@ -153,7 +167,7 @@ fun CarsList(navHost: NavHostController) {
|
|
|
|
|
|
Image(
|
|
|
painter = painter,
|
|
|
- contentDescription = "Фото автомобиля",
|
|
|
+ contentDescription = "Фото ресторана",
|
|
|
modifier = Modifier
|
|
|
.fillMaxWidth()
|
|
|
.height(200.dp),
|
|
@@ -165,33 +179,33 @@ fun CarsList(navHost: NavHostController) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Кнопка "Добавить новый автомобиль" только для администраторов
|
|
|
- val userId = Constants.supabase.auth.currentUserOrNull()?.id
|
|
|
- val userIdString = userId?.toString() ?: ""
|
|
|
|
|
|
- if (!loadingUsers && userId != null) {
|
|
|
- val user = users.find { it.id_user == userIdString }
|
|
|
- if (user != null) {
|
|
|
- Spacer(modifier = Modifier.weight(1f)) // Занимаем оставшееся пространство для размещения кнопки внизу
|
|
|
- Button(
|
|
|
- onClick = { navHost.navigate("InsertCar") },
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .height(56.dp)
|
|
|
- .padding(8.dp)
|
|
|
- .padding(bottom = 24.dp),
|
|
|
- shape = RoundedCornerShape(12.dp), // Кнопка с более квадратными углами
|
|
|
- colors = ButtonDefaults.buttonColors(
|
|
|
- containerColor = Color(0XFFcce6ff),
|
|
|
- contentColor = Color.White
|
|
|
- )
|
|
|
- ) {
|
|
|
- Text("Добавить новый автомобиль", fontSize = 18.sp)
|
|
|
- }
|
|
|
- }
|
|
|
+// val userId = Constants.supabase.auth.currentUserOrNull()?.id
|
|
|
+// val userIdString = userId?.toString() ?: ""
|
|
|
+//
|
|
|
+// if (!loadingUsers && userId != null) {
|
|
|
+// val user = users.find { it.id_user == userIdString }
|
|
|
+// if (user != null) {
|
|
|
+// Spacer(modifier = Modifier.weight(1f)) // Занимаем оставшееся пространство для размещения кнопки внизу
|
|
|
+// Button(
|
|
|
+// onClick = { navHost.navigate("InsertCar") },
|
|
|
+// modifier = Modifier
|
|
|
+// .fillMaxWidth()
|
|
|
+// .height(56.dp)
|
|
|
+// .padding(8.dp)
|
|
|
+// .padding(bottom = 24.dp),
|
|
|
+// shape = RoundedCornerShape(12.dp), // Кнопка с более квадратными углами
|
|
|
+// colors = ButtonDefaults.buttonColors(
|
|
|
+// containerColor = Color(0XFFcce6ff),
|
|
|
+// contentColor = Color.White
|
|
|
+// )
|
|
|
+// ) {
|
|
|
+// Text("Добавить новый автомобиль", fontSize = 18.sp)
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
|
|
|
|