Implement show and clear errorMessages in Snackbar

pull/1461/head
TM 1 year ago
parent 3ffbe20b1d
commit 2d26760595

@ -93,6 +93,7 @@ fun NiaApp(appState: NiaAppState, modifier: Modifier = Modifier) {
val snackbarHostState = remember { SnackbarHostState() } val snackbarHostState = remember { SnackbarHostState() }
val isOffline by appState.isOffline.collectAsStateWithLifecycle() val isOffline by appState.isOffline.collectAsStateWithLifecycle()
val errorMessage by appState.errorMessage.collectAsStateWithLifecycle()
// If user is not connected to the internet show a snack bar to inform them. // If user is not connected to the internet show a snack bar to inform them.
val notConnectedMessage = stringResource(R.string.not_connected) val notConnectedMessage = stringResource(R.string.not_connected)
@ -104,6 +105,19 @@ fun NiaApp(appState: NiaAppState, modifier: Modifier = Modifier) {
) )
} }
} }
LaunchedEffect(errorMessage) {
errorMessage?.let {
val snackBarResult = snackbarHostState.showSnackbar(
message = it,
actionLabel = "Continue",
duration = Indefinite
) == ActionPerformed
if (snackBarResult) {
appState.clearErrorMessage()
}
}
}
NiaApp( NiaApp(
appState = appState, appState = appState,

Loading…
Cancel
Save