Опа, пофикисили отображение
This commit is contained in:
parent
f76e0ff450
commit
17a4568123
@ -55,6 +55,7 @@ import com.example.myapplication.R
|
||||
import com.example.myapplication.database.entities.composeui.AppViewModelProvider
|
||||
import com.example.myapplication.database.entities.composeui.CartUiState
|
||||
import com.example.myapplication.database.entities.composeui.CartViewModel
|
||||
import com.example.myapplication.database.entities.composeui.CurrentUserViewModel
|
||||
import com.example.myapplication.database.entities.model.Item
|
||||
import com.example.myapplication.database.entities.model.ItemFromCart
|
||||
import com.example.myapplication.ui.theme.PmudemoTheme
|
||||
@ -64,13 +65,15 @@ import org.threeten.bp.format.DateTimeFormatter
|
||||
|
||||
@Composable
|
||||
fun Cart(
|
||||
viewModel: CartViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
||||
viewModel: CartViewModel = viewModel(factory = AppViewModelProvider.Factory),
|
||||
currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
||||
) {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val cartUiState = viewModel.cartUiState
|
||||
var getUser by remember { mutableStateOf(currentUserViewModel.user) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.refreshState()
|
||||
getUser?.uid?.let { viewModel.refreshState(it) }
|
||||
}
|
||||
|
||||
Cart(
|
||||
|
@ -187,7 +187,7 @@ fun Navhost(
|
||||
) {
|
||||
composable(Screen.BikeList.route) { BikeList(navController) }
|
||||
composable(Screen.RentList.route) { RentList(navController, 1) }
|
||||
composable(Screen.Cart.route) { Cart() }
|
||||
composable(Screen.Cart.route) { Cart(currentUserViewModel = currentUserViewModel) }
|
||||
composable(Screen.UserProfile.route) { UserProfile(isDarkTheme, dataStore, currentUserViewModel = currentUserViewModel) }
|
||||
composable(
|
||||
Screen.BikeEdit.route,
|
||||
|
@ -21,12 +21,12 @@ class CartViewModel(
|
||||
private val rentItemRepository: RentItemRepository,
|
||||
private val userRepository: UserRepository,
|
||||
) : ViewModel() {
|
||||
private val userUid: Int = 1
|
||||
//private val userUid: Int = 1
|
||||
var cartUiState by mutableStateOf(CartUiState())
|
||||
private set
|
||||
|
||||
suspend fun refreshState() {
|
||||
val cart = userRepository.getCartByUser(userUid)
|
||||
suspend fun refreshState(userId: Int) {
|
||||
val cart = userRepository.getCartByUser(userId)
|
||||
cartUiState = CartUiState(cart)
|
||||
}
|
||||
|
||||
@ -45,12 +45,12 @@ class CartViewModel(
|
||||
)
|
||||
}
|
||||
userItemRepository.deleteUserItems(userId)
|
||||
refreshState()
|
||||
refreshState(userId)
|
||||
}
|
||||
|
||||
suspend fun removeFromCart(user: Int, item: Item, count: Int = 1) {
|
||||
userItemRepository.deleteUserItem(UserItemCrossRef(user, item.uid, count))
|
||||
refreshState()
|
||||
refreshState(user)
|
||||
}
|
||||
|
||||
suspend fun updateFromCart(userId: Int, item: Item, count: Int, availableCount: Int)
|
||||
@ -62,7 +62,7 @@ class CartViewModel(
|
||||
if (count > availableCount)
|
||||
return false
|
||||
userItemRepository.updateUserItem(UserItemCrossRef(userId, item.uid, count))
|
||||
refreshState()
|
||||
refreshState(userId)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,19 @@
|
||||
{
|
||||
"id": 2,
|
||||
"login": "hello",
|
||||
"password": "hello"
|
||||
"password": "hello",
|
||||
"items": [
|
||||
{
|
||||
"id": 6,
|
||||
"count": 1,
|
||||
"bikeId": 3
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"count": 1,
|
||||
"bikeId": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
@ -45,7 +57,14 @@
|
||||
{
|
||||
"id": 7,
|
||||
"login": "1",
|
||||
"password": "1"
|
||||
"password": "1",
|
||||
"items": [
|
||||
{
|
||||
"id": 4,
|
||||
"count": 1,
|
||||
"bikeId": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
|
Loading…
Reference in New Issue
Block a user