Repository: android/compose-samples
File: Jetcaster/wear/src/main/java/com/example/jetcaster/ui/library/PodcastsScreen.kt (Kotlin)

Code before:
) {
    val uiState by podcastViewModel.uiState.collectAsStateWithLifecycle()

    val modifiedState = when (uiState) {
        is PodcastsScreenState.Loaded -> {
            val modifiedPodcast = (uiState as PodcastsScreenState.Loaded).podcastList.map {
                it.takeIf { it.title.isNotEmpty() }
                    ?: it.copy(title = stringResource(id = R.string.no_title))
            }

            PodcastsScreenState.Loaded(modifiedPodcast)
        }

        PodcastsScreenState.Failed,
        PodcastsScreenState.Loading,
        -> uiState
    }

    PodcastsScreen(
        podcastsScreenState = modifiedState,
        onPodcastsItemClick = onPodcastsItemClick
    )

    if (modifiedState == PodcastsScreenState.Failed) {
        Dialog(
            showDialog = true,
            onDismissRequest = onErrorDialogCancelClick,
            scrollState = rememberScalingLazyListState(),
        ) {
            Alert(
                title = {
                    Text(
                        text = stringResource(R.string.podcasts_no_podcasts),
                        color = MaterialTheme.colors.onBackground,
                        textAlign = TextAlign.Center,
                        style = MaterialTheme.typography.title3,
                    )
                },
            ) {
                item {
                    Row(
                        verticalAlignment = Alignment.CenterVertically,
                    ) {

                        Button(
                            imageVector = Icons.Default.Close,
                            contentDescription = stringResource(
                                id = R.string
                                    .podcasts_failed_dialog_cancel_button_content_description,
                            ),
                            onClick = onErrorDialogCancelClick,

Review comment (bug):
This can be simplified as:
```suggestion
            showDialog = modifiedState == PodcastsScreenState.Failed,
```

...and remove the outer if clause

Code after:
) {
    val uiState by podcastsViewModel.uiState.collectAsStateWithLifecycle()

    val modifiedState = when (uiState) {
        is PodcastsScreenState.Loaded -> {
            val modifiedPodcast = (uiState as PodcastsScreenState.Loaded).podcastList.map {
                it.takeIf { it.title.isNotEmpty() }
                    ?: it.copy(title = stringResource(id = R.string.no_title))
            }

            PodcastsScreenState.Loaded(modifiedPodcast)
        }

        PodcastsScreenState.Empty,
        PodcastsScreenState.Loading,
        -> uiState
    }

    PodcastsScreen(
        podcastsScreenState = modifiedState,
        onPodcastsItemClick = onPodcastsItemClick
    )

    Dialog(
        showDialog = modifiedState == PodcastsScreenState.Empty,
        onDismissRequest = onErrorDialogCancelClick,
        scrollState = rememberScalingLazyListState(),
    ) {
        Alert(
            title = {
                Text(
                    text = stringResource(R.string.podcasts_no_podcasts),
                    color = MaterialTheme.colors.onBackground,
                    textAlign = TextAlign.Center,
                    style = MaterialTheme.typography.title3,
                )
            },
        ) {
            item {
                Row(
                    verticalAlignment = Alignment.CenterVertically,
                ) {

                    Button(
                        imageVector = Icons.Default.Close,
                        contentDescription = stringResource(
                            id = R.string
                                .podcasts_failed_dialog_cancel_button_content_description,
                        ),
                        onClick = onErrorDialogCancelClick,
                        modifier = Modifier