Repository: android/nowinandroid
File: feature/search/src/main/java/com/google/samples/apps/nowinandroid/feature/search/SearchScreen.kt (Kotlin)

Code before:
        )
        when (searchResultUiState) {
            SearchResultUiState.Loading,
            SearchResultUiState.LoadFailed,
            -> Unit

            SearchResultUiState.SearchNotReady -> SearchNotReadyBody()
            SearchResultUiState.EmptyQuery,
            -> {
                if (recentSearchesUiState is RecentSearchQueriesUiState.Success) {
                    RecentSearchesBody(
                        onClearRecentSearches = onClearRecentSearches,
                        onRecentSearchClicked = {
                            onSearchQueryChanged(it)
                            onSearchTriggered(it)
                        },
                        recentSearchQueries = recentSearchesUiState.recentQueries.map { it.query },
                    )
                }
            }

            is SearchResultUiState.Success -> {
                if (searchResultUiState.isEmpty()) {
                    EmptySearchResultBody(
                        onInterestsClick = onInterestsClick,
                        searchQuery = searchQuery,
                    )
                    if (recentSearchesUiState is RecentSearchQueriesUiState.Success) {
                        RecentSearchesBody(
                            onClearRecentSearches = onClearRecentSearches,
                            onRecentSearchClicked = {
                                onSearchQueryChanged(it)
                                onSearchTriggered(it)
                            },
                            recentSearchQueries = recentSearchesUiState.recentQueries.map { it.query },
                        )
                    }
                } else {
                    SearchResultBody(
                        topics = searchResultUiState.topics,
                        onFollowButtonClick = onFollowButtonClick,
                        onNewsResourcesCheckedChanged = onNewsResourcesCheckedChanged,
                        onSearchTriggered = onSearchTriggered,
                        onTopicClick = onTopicClick,
                        newsResources = searchResultUiState.newsResources,
                        searchQuery = searchQuery,
                    )
                }
            }
        }
        Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))

Review comment (suggestion):
Below is the current condition block:
```
is SearchResultUiState.Success -> {
    if (searchResultUiState.isEmpty()) {
        EmptySearchResultBody() // This object is not used if the below condition is true
        if (recentSearchesUiState is RecentSearchQueriesUiState.Success) {
            RecentSearchesBody()
        }
    } else {
        SearchResultBody()
    }
}
```

Should we change this to if/else so that we don't create `EmptySearchResultBody` needlessly?
```
if (recentSearchesUiState is RecentSearchQueriesUiState.Success) {
    RecentSearchesBody()
} else {
    EmptySearchResultBody()
}
```

Code after:
            SearchResultUiState.Loading,
            SearchResultUiState.LoadFailed,
            -> Unit

            SearchResultUiState.SearchNotReady -> SearchNotReadyBody()
            SearchResultUiState.EmptyQuery,
            -> {
                if (recentSearchesUiState is RecentSearchQueriesUiState.Success) {
                    RecentSearchesBody(
                        onClearRecentSearches = onClearRecentSearches,
                        onRecentSearchClicked = {
                            onSearchQueryChanged(it)
                            onSearchTriggered(it)
                        },
                        recentSearchQueries = recentSearchesUiState.recentQueries.map { it.query },
                    )
                }
            }

            is SearchResultUiState.Success -> {
                if (searchResultUiState.isEmpty()) {
                    EmptySearchResultBody(
                        onInterestsClick = onInterestsClick,
                        searchQuery = searchQuery,
                    )
                    if (recentSearchesUiState is RecentSearchQueriesUiState.Success) {
                        RecentSearchesBody(
                            onClearRecentSearches = onClearRecentSearches,
                            onRecentSearchClicked = {
                                onSearchQueryChanged(it)
                                onSearchTriggered(it)
                            },
                            recentSearchQueries = recentSearchesUiState.recentQueries.map { it.query },
                        )
                    }
                } else {
                    SearchResultBody(
                        topics = searchResultUiState.topics,
                        onFollowButtonClick = onFollowButtonClick,
                        onNewsResourcesCheckedChanged = onNewsResourcesCheckedChanged,
                        onSearchTriggered = onSearchTriggered,
                        onTopicClick = onTopicClick,
                        newsResources = searchResultUiState.newsResources,
                        searchQuery = searchQuery,
                    )
                }
            }
        }
        Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
    }
}