-
Notifications
You must be signed in to change notification settings - Fork 11.8k
fix: ensure user message after adding or editing a task is shown only once even after navigation #1047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: ensure user message after adding or editing a task is shown only once even after navigation #1047
Changes from all commits
0ae6330
20b4ef7
a68f24b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,6 @@ import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberUpdatedState | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.dimensionResource | ||
|
@@ -66,10 +65,8 @@ import com.example.android.architecture.blueprints.todoapp.util.TasksTopAppBar | |
|
||
@Composable | ||
fun TasksScreen( | ||
@StringRes userMessage: Int, | ||
onAddTask: () -> Unit, | ||
onTaskClick: (Task) -> Unit, | ||
onUserMessageDisplayed: () -> Unit, | ||
openDrawer: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
viewModel: TasksViewModel = hiltViewModel(), | ||
KahiloMassango marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -95,6 +92,7 @@ fun TasksScreen( | |
} | ||
) { paddingValues -> | ||
val uiState by viewModel.uiState.collectAsStateWithLifecycle() | ||
val userMessageResultCode by viewModel.userMessageResultCode.collectAsStateWithLifecycle() | ||
|
||
TasksContent( | ||
loading = uiState.isLoading, | ||
|
@@ -118,11 +116,9 @@ fun TasksScreen( | |
} | ||
|
||
// Check if there's a userMessage to show to the user | ||
val currentOnUserMessageDisplayed by rememberUpdatedState(onUserMessageDisplayed) | ||
LaunchedEffect(userMessage) { | ||
if (userMessage != 0) { | ||
viewModel.showEditResultMessage(userMessage) | ||
currentOnUserMessageDisplayed() | ||
LaunchedEffect(userMessageResultCode) { | ||
if (userMessageResultCode != 0) { | ||
viewModel.showEditResultMessage(userMessageResultCode) | ||
} | ||
} | ||
Comment on lines
+119
to
123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The message will be displayed because the userMessageResultCode will be set to 0 after one message is displayed, then the next one will also be displayed because the code will be different from 0. |
||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.