Готово
This commit is contained in:
@@ -3,6 +3,7 @@ package com.example.myapplication.components
|
||||
|
||||
import ButtonNice
|
||||
import TextNice
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
@@ -25,6 +26,7 @@ import com.example.myapplication.database.AppDb
|
||||
import com.example.myapplication.database.entities.Product
|
||||
import com.example.myapplication.viewModels.UserViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import myColor4
|
||||
|
||||
@@ -36,9 +38,7 @@ fun Cart(navController: NavController, userViewModel: UserViewModel = viewModel(
|
||||
val sumPrice = remember { mutableStateOf(0.0) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
if (userViewModel.getUserId() == 0) {
|
||||
navController.navigate("authorization")
|
||||
} else {
|
||||
|
||||
userViewModel.getUserProductCartById(userViewModel.getUserId()).collect {data ->
|
||||
products.clear()
|
||||
sumPrice.value = 0.0;
|
||||
@@ -46,7 +46,6 @@ fun Cart(navController: NavController, userViewModel: UserViewModel = viewModel(
|
||||
sumPrice.value += it.price
|
||||
products.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,12 +54,27 @@ fun Cart(navController: NavController, userViewModel: UserViewModel = viewModel(
|
||||
TextNice("Корзина")
|
||||
}
|
||||
|
||||
item {
|
||||
for (product in products){
|
||||
ProductCardInCart(product.name, product.price, product.img, { navController.navigate("product/" + product.productId)})
|
||||
// item {
|
||||
// for (product in products){
|
||||
// ProductCardInCart(product.name, product.price, product.img){
|
||||
// coroutineScope.launch {
|
||||
// userViewModel.deleteCartProduct(userViewModel.getUserId(), product.productId!!)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
item{
|
||||
products.forEach{
|
||||
ProductCardInCart(it.name, it.price, it.img){
|
||||
coroutineScope.launch {
|
||||
Log.d("delete", "мама макса б")
|
||||
userViewModel.deleteCartProduct(userViewModel.getUserId(), it.productId!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
item {
|
||||
ButtonNice(text = "Оплатить: " + sumPrice.value.toString() + "Р", color = myColor4)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user