Fix: Labels screen navigation and Create Item error; Labels screen now displays a proper navigation bar by utilizing MainScaffold; Fixed "Create Item" functionality by ensuring ItemEditScreen is navigated to with a null itemId for new item creation, preventing an API error; Added navigateToLabelEdit function to NavigationActions.
This commit is contained in:
@@ -90,7 +90,10 @@ fun NavGraph(
|
||||
)
|
||||
}
|
||||
composable(Screen.LabelsList.route) {
|
||||
LabelsListScreen(navController = navController)
|
||||
LabelsListScreen(
|
||||
currentRoute = currentRoute,
|
||||
navigationActions = navigationActions
|
||||
)
|
||||
}
|
||||
composable(route = Screen.LocationsList.route) {
|
||||
LocationsListScreen(
|
||||
|
||||
@@ -49,6 +49,13 @@ class NavigationActions(private val navController: NavHostController) {
|
||||
}
|
||||
// [END_ENTITY: Function('navigateToLabels')]
|
||||
|
||||
// [ENTITY: Function('navigateToLabelEdit')]
|
||||
fun navigateToLabelEdit(labelId: String? = null) {
|
||||
Timber.i("[INFO][ACTION][navigate_to_label_edit] Navigating to Label Edit with ID: %s", labelId)
|
||||
navController.navigate(Screen.LabelEdit.createRoute(labelId))
|
||||
}
|
||||
// [END_ENTITY: Function('navigateToLabelEdit')]
|
||||
|
||||
// [ENTITY: Function('navigateToSearch')]
|
||||
fun navigateToSearch() {
|
||||
Timber.i("[INFO][ACTION][navigate_to_search] Navigating to Search.")
|
||||
@@ -77,7 +84,7 @@ class NavigationActions(private val navController: NavHostController) {
|
||||
// [ENTITY: Function('navigateToCreateItem')]
|
||||
fun navigateToCreateItem() {
|
||||
Timber.i("[INFO][ACTION][navigate_to_create_item] Navigating to Create Item.")
|
||||
navController.navigate(Screen.ItemEdit.createRoute("new"))
|
||||
navController.navigate(Screen.ItemEdit.createRoute())
|
||||
}
|
||||
// [END_ENTITY: Function('navigateToCreateItem')]
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.homebox.lens.R
|
||||
import com.homebox.lens.navigation.NavigationActions
|
||||
import com.homebox.lens.ui.common.MainScaffold
|
||||
@@ -56,7 +56,7 @@ fun ItemEditScreen(
|
||||
currentRoute: String?,
|
||||
navigationActions: NavigationActions,
|
||||
itemId: String?,
|
||||
viewModel: ItemEditViewModel = viewModel(),
|
||||
viewModel: ItemEditViewModel = hiltViewModel(),
|
||||
onSaveSuccess: () -> Unit
|
||||
) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
|
||||
@@ -40,10 +40,11 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.navigation.NavController
|
||||
import com.homebox.lens.R
|
||||
import com.homebox.lens.domain.model.Label
|
||||
import com.homebox.lens.navigation.NavigationActions
|
||||
import com.homebox.lens.navigation.Screen
|
||||
import com.homebox.lens.ui.common.MainScaffold
|
||||
import timber.log.Timber
|
||||
// [END_IMPORTS]
|
||||
|
||||
@@ -55,35 +56,24 @@ import timber.log.Timber
|
||||
* @param navController Контроллер навигации для перемещения между экранами.
|
||||
* @param viewModel ViewModel, предоставляющая состояние UI для экрана меток.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LabelsListScreen(
|
||||
navController: NavController,
|
||||
currentRoute: String?,
|
||||
navigationActions: NavigationActions,
|
||||
viewModel: LabelsListViewModel = hiltViewModel()
|
||||
) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
|
||||
MainScaffold(
|
||||
topBarTitle = stringResource(id = R.string.screen_title_labels),
|
||||
currentRoute = currentRoute,
|
||||
navigationActions = navigationActions
|
||||
) { paddingValues ->
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(text = stringResource(id = R.string.screen_title_labels)) },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = {
|
||||
Timber.i("[INFO][ACTION][navigate_up] Navigate up initiated.")
|
||||
navController.navigateUp()
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.content_desc_navigate_back)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
FloatingActionButton(onClick = {
|
||||
Timber.i("[INFO][ACTION][navigate_to_label_edit] FAB clicked: Navigate to create new label screen.")
|
||||
navController.navigate(Screen.LabelEdit.createRoute())
|
||||
navigationActions.navigateToLabelEdit(null)
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Add,
|
||||
@@ -91,13 +81,13 @@ fun LabelsListScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
) { paddingValues ->
|
||||
) { innerPaddingValues ->
|
||||
val currentState = uiState
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues),
|
||||
.padding(innerPaddingValues), // Use innerPaddingValues here
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
when (currentState) {
|
||||
@@ -115,7 +105,7 @@ fun LabelsListScreen(
|
||||
labels = currentState.labels,
|
||||
onLabelClick = { label ->
|
||||
Timber.i("[INFO][ACTION][navigate_to_label_edit] Label clicked: ${label.id}. Navigating to label edit screen.")
|
||||
navController.navigate(Screen.LabelEdit.createRoute(label.id))
|
||||
navigationActions.navigateToLabelEdit(label.id)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -124,6 +114,7 @@ fun LabelsListScreen(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// [END_ENTITY: Function('LabelsListScreen')]
|
||||
|
||||
// [ENTITY: Function('LabelsList')]
|
||||
|
||||
Reference in New Issue
Block a user