package eu.friedcutlet.yokan.ui.status import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import eu.friedcutlet.yokan.domain.ProfileId import eu.friedcutlet.yokan.services.notifications.InAppNotifications /** * In-app toasts: background services and screens post to [InAppNotifications]; messages visible to * [profileId] surface through [snackbarHostState] instead of OS-level popups. */ @Composable fun InAppSnackbarEffect(snackbarHostState: SnackbarHostState, profileId: ProfileId) { LaunchedEffect(snackbarHostState, profileId) { InAppNotifications.messages.collect { msg -> if (!msg.visibleTo(profileId)) return@collect val text = when { msg.title.isNotBlank() && msg.message.isNotBlank() -> "${msg.title}: ${msg.message}" else -> msg.title.ifBlank { msg.message } } if (text.isNotBlank()) snackbarHostState.showSnackbar(text) } } }