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) {
|
composable(Screen.LabelsList.route) {
|
||||||
LabelsListScreen(navController = navController)
|
LabelsListScreen(
|
||||||
|
currentRoute = currentRoute,
|
||||||
|
navigationActions = navigationActions
|
||||||
|
)
|
||||||
}
|
}
|
||||||
composable(route = Screen.LocationsList.route) {
|
composable(route = Screen.LocationsList.route) {
|
||||||
LocationsListScreen(
|
LocationsListScreen(
|
||||||
|
|||||||
@@ -49,6 +49,13 @@ class NavigationActions(private val navController: NavHostController) {
|
|||||||
}
|
}
|
||||||
// [END_ENTITY: Function('navigateToLabels')]
|
// [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')]
|
// [ENTITY: Function('navigateToSearch')]
|
||||||
fun navigateToSearch() {
|
fun navigateToSearch() {
|
||||||
Timber.i("[INFO][ACTION][navigate_to_search] Navigating to Search.")
|
Timber.i("[INFO][ACTION][navigate_to_search] Navigating to Search.")
|
||||||
@@ -77,7 +84,7 @@ class NavigationActions(private val navController: NavHostController) {
|
|||||||
// [ENTITY: Function('navigateToCreateItem')]
|
// [ENTITY: Function('navigateToCreateItem')]
|
||||||
fun navigateToCreateItem() {
|
fun navigateToCreateItem() {
|
||||||
Timber.i("[INFO][ACTION][navigate_to_create_item] Navigating to Create Item.")
|
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')]
|
// [END_ENTITY: Function('navigateToCreateItem')]
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.unit.dp
|
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.R
|
||||||
import com.homebox.lens.navigation.NavigationActions
|
import com.homebox.lens.navigation.NavigationActions
|
||||||
import com.homebox.lens.ui.common.MainScaffold
|
import com.homebox.lens.ui.common.MainScaffold
|
||||||
@@ -56,7 +56,7 @@ fun ItemEditScreen(
|
|||||||
currentRoute: String?,
|
currentRoute: String?,
|
||||||
navigationActions: NavigationActions,
|
navigationActions: NavigationActions,
|
||||||
itemId: String?,
|
itemId: String?,
|
||||||
viewModel: ItemEditViewModel = viewModel(),
|
viewModel: ItemEditViewModel = hiltViewModel(),
|
||||||
onSaveSuccess: () -> Unit
|
onSaveSuccess: () -> Unit
|
||||||
) {
|
) {
|
||||||
val uiState by viewModel.uiState.collectAsState()
|
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.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavController
|
|
||||||
import com.homebox.lens.R
|
import com.homebox.lens.R
|
||||||
import com.homebox.lens.domain.model.Label
|
import com.homebox.lens.domain.model.Label
|
||||||
|
import com.homebox.lens.navigation.NavigationActions
|
||||||
import com.homebox.lens.navigation.Screen
|
import com.homebox.lens.navigation.Screen
|
||||||
|
import com.homebox.lens.ui.common.MainScaffold
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
// [END_IMPORTS]
|
// [END_IMPORTS]
|
||||||
|
|
||||||
@@ -55,35 +56,24 @@ import timber.log.Timber
|
|||||||
* @param navController Контроллер навигации для перемещения между экранами.
|
* @param navController Контроллер навигации для перемещения между экранами.
|
||||||
* @param viewModel ViewModel, предоставляющая состояние UI для экрана меток.
|
* @param viewModel ViewModel, предоставляющая состояние UI для экрана меток.
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LabelsListScreen(
|
fun LabelsListScreen(
|
||||||
navController: NavController,
|
currentRoute: String?,
|
||||||
|
navigationActions: NavigationActions,
|
||||||
viewModel: LabelsListViewModel = hiltViewModel()
|
viewModel: LabelsListViewModel = hiltViewModel()
|
||||||
) {
|
) {
|
||||||
val uiState by viewModel.uiState.collectAsState()
|
val uiState by viewModel.uiState.collectAsState()
|
||||||
|
|
||||||
|
MainScaffold(
|
||||||
|
topBarTitle = stringResource(id = R.string.screen_title_labels),
|
||||||
|
currentRoute = currentRoute,
|
||||||
|
navigationActions = navigationActions
|
||||||
|
) { paddingValues ->
|
||||||
Scaffold(
|
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 = {
|
||||||
FloatingActionButton(onClick = {
|
FloatingActionButton(onClick = {
|
||||||
Timber.i("[INFO][ACTION][navigate_to_label_edit] FAB clicked: Navigate to create new label screen.")
|
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(
|
Icon(
|
||||||
imageVector = Icons.Default.Add,
|
imageVector = Icons.Default.Add,
|
||||||
@@ -91,13 +81,13 @@ fun LabelsListScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { innerPaddingValues ->
|
||||||
val currentState = uiState
|
val currentState = uiState
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(paddingValues),
|
.padding(innerPaddingValues), // Use innerPaddingValues here
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
when (currentState) {
|
when (currentState) {
|
||||||
@@ -115,7 +105,7 @@ fun LabelsListScreen(
|
|||||||
labels = currentState.labels,
|
labels = currentState.labels,
|
||||||
onLabelClick = { label ->
|
onLabelClick = { label ->
|
||||||
Timber.i("[INFO][ACTION][navigate_to_label_edit] Label clicked: ${label.id}. Navigating to label edit screen.")
|
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')]
|
// [END_ENTITY: Function('LabelsListScreen')]
|
||||||
|
|
||||||
// [ENTITY: Function('LabelsList')]
|
// [ENTITY: Function('LabelsList')]
|
||||||
|
|||||||
Reference in New Issue
Block a user