mirror of
https://github.com/wismna/DoNext.git
synced 2025-12-06 00:02:40 -05:00
Prevent navigation to current destination
This commit is contained in:
@@ -57,7 +57,7 @@ fun MenuScreen(
|
||||
},
|
||||
icon = { Icon(Icons.Default.Today, contentDescription = "Due Today") },
|
||||
selected = currentDestination is AppDestination.DueTodayList,
|
||||
onClick = { viewModel.navigateTo(AppDestination.DueTodayList.route) },
|
||||
onClick = { viewModel.navigateTo(AppDestination.DueTodayList.route, currentDestination.route) },
|
||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||
)
|
||||
HorizontalDivider()
|
||||
@@ -73,7 +73,7 @@ fun MenuScreen(
|
||||
icon = { Icon(Icons.Default.LineWeight, contentDescription = list.name) },
|
||||
selected = currentDestination is AppDestination.TaskList &&
|
||||
currentDestination.taskListId == list.id,
|
||||
onClick = { viewModel.navigateTo("taskList/${list.id}") },
|
||||
onClick = { viewModel.navigateTo("taskList/${list.id}", currentDestination.route) },
|
||||
badge = {
|
||||
if (list.overdueCount > 0) {
|
||||
Badge { Text(list.overdueCount.toString()) }
|
||||
@@ -90,14 +90,14 @@ fun MenuScreen(
|
||||
label = { Text("Recycle Bin") },
|
||||
icon = { Icon(Icons.Default.Delete, contentDescription = "Recycle Bin") },
|
||||
selected = currentDestination is AppDestination.RecycleBin,
|
||||
onClick = { viewModel.navigateTo(AppDestination.RecycleBin.route) },
|
||||
onClick = { viewModel.navigateTo(AppDestination.RecycleBin.route, currentDestination.route) },
|
||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||
)
|
||||
NavigationDrawerItem(
|
||||
label = { Text("Edit Lists") },
|
||||
icon = { Icon(Icons.Default.EditNote, contentDescription = "Edit Lists") },
|
||||
selected = currentDestination is AppDestination.ManageLists,
|
||||
onClick = { viewModel.navigateTo(AppDestination.ManageLists.route) },
|
||||
onClick = { viewModel.navigateTo(AppDestination.ManageLists.route, currentDestination.route) },
|
||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.wismna.geoffroy.donext.domain.model.AppDestination
|
||||
import com.wismna.geoffroy.donext.domain.model.TaskListWithOverdue
|
||||
import com.wismna.geoffroy.donext.domain.usecase.GetDueTodayTasksUseCase
|
||||
import com.wismna.geoffroy.donext.domain.usecase.GetTaskListsWithOverdueUseCase
|
||||
@@ -42,9 +43,11 @@ class MenuViewModel @Inject constructor(
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
fun navigateTo(route: String) {
|
||||
viewModelScope.launch {
|
||||
uiEventBus.send(UiEvent.Navigate(route))
|
||||
fun navigateTo(route: String, currentRoute: String) {
|
||||
if (route != currentRoute) {
|
||||
viewModelScope.launch {
|
||||
uiEventBus.send(UiEvent.Navigate(route))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user