Untitled
unknown
plain_text
2 years ago
2.8 kB
0
Indexable
Never
package com.kroger.pos.cart.ui import androidx.compose.material.Scaffold import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import com.kroger.pos.cart.pub.nav.OrderNavRoute import com.kroger.pos.cart.viewmodel.OrderViewModel import com.kroger.pos.search.pub.SearchViewProvider @Composable fun HomeScreen(searchViewProvider: SearchViewProvider) { val navController = rememberNavController() val orderViewModelStoreOwner = checkNotNull(LocalViewModelStoreOwner.current) val orderViewModel = hiltViewModel<OrderViewModel>(orderViewModelStoreOwner) val scanError by orderViewModel.updateErrors.collectAsState() val currentBackStackEntry by navController.currentBackStackEntryAsState() Scaffold( topBar = { OrderToolbar( searchViewProvider = searchViewProvider, navController = navController, currentRoute = OrderNavRoute.byId(currentBackStackEntry?.destination?.route), goBack = { navController.popBackStack(OrderNavRoute.CART.id, false) }, ) }, ) { NavHost(navController = navController, startDestination = OrderNavRoute.CART.id) { composable(OrderNavRoute.CART.id) { OrderView( addLoyalty = orderViewModel::addLoyalty, errorStream = orderViewModel.updateErrors, error = scanError, orderFlow = orderViewModel.order, stepperAction = orderViewModel::changeCartQuantity, expandedItemFlow = orderViewModel.expandedIndex, setExpandedItem = orderViewModel::setExpandedIndex, updateItemPrice = orderViewModel::updateItemPrice, itemUpdateState = orderViewModel.itemUpdateState, clearUpdateState = orderViewModel::clearItemUpdateState, navController = navController, onDismissClicked = { orderViewModel.clearError() } ) } composable(OrderNavRoute.SEARCH.id) { searchViewProvider.SearchResults( navController, ) } composable(OrderNavRoute.SUMMARY.id) { OrderSummaryScreen( navController, ) } } } }