InAppSnackbarEffect.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/status/InAppSnackbarEffect.kt
1package eu.friedcutlet.yokan.ui.status23import androidx.compose.material3.SnackbarHostState4import androidx.compose.runtime.Composable5import androidx.compose.runtime.LaunchedEffect6import eu.friedcutlet.yokan.domain.ProfileId7import eu.friedcutlet.yokan.services.notifications.InAppNotifications89/**10 * In-app toasts: background services and screens post to [InAppNotifications]; messages visible to11 * [profileId] surface through [snackbarHostState] instead of OS-level popups.12 */13@Composable14fun InAppSnackbarEffect(snackbarHostState: SnackbarHostState, profileId: ProfileId) {15 LaunchedEffect(snackbarHostState, profileId) {16 InAppNotifications.messages.collect { msg ->17 if (!msg.visibleTo(profileId)) return@collect18 val text = when {19 msg.title.isNotBlank() && msg.message.isNotBlank() -> "${msg.title}: ${msg.message}"20 else -> msg.title.ifBlank { msg.message }21 }22 if (text.isNotBlank()) snackbarHostState.showSnackbar(text)23 }24 }25}26