Repository: android/compose-samples
File: JetNews/app/src/main/java/com/example/jetnews/ui/interests/InterestsScreen.kt (Kotlin)

Code before:
        val screenModifier = Modifier.padding(innerPadding)
        InterestScreenContent(
            isTabRowExpanded, currentSection, onTabChange, tabContent, screenModifier
        )
    }
}

@Composable
fun rememberTabContent(interestsViewModel: InterestsViewModel): List<TabContent> {
    // UiState of the InterestsScreen
    val uiState by interestsViewModel.uiState.collectAsState()

    // Describe the screen sections here since each section needs 2 states and 1 event.
    // Pass them to the stateless InterestsScreen using a tabContent.
    val topicsSection = TabContent(Sections.Topics) {
        val selectedTopics by interestsViewModel.selectedTopics.collectAsState()
        TabContent(
            sections = uiState.topics,
            selectedTopics = selectedTopics,
            onTopicSelect = { interestsViewModel.toggleTopicSelection(it) }
        )
    }

    val peopleSection = TabContent(Sections.People) {
        val selectedPeople by interestsViewModel.selectedPeople.collectAsState()
        val section = listOf(InterestSection("", uiState.people))
        TabContent(
            sections = section,
            selectedTopics = selectedPeople.map { TopicSelection("people", it) }.toSet(),
            onTopicSelect = { interestsViewModel.togglePersonSelected(it.topic) }
        )
    }

    val publicationSection = TabContent(Sections.Publications) {
        val selectedPublications by interestsViewModel.selectedPublications.collectAsState()
        val section = listOf(InterestSection("", uiState.publications))
        TabContent(
            sections = section,
            selectedTopics = selectedPublications
                .map { TopicSelection("publications", it) }.toSet(),
            onTopicSelect = { interestsViewModel.togglePublicationSelected(it.topic) }
        )
    }

    return listOf(topicsSection, peopleSection, publicationSection)
}

/**
 * Displays a tab row with [currentSection] selected and the body of the corresponding [tabContent].
 *
 * @param isTabRowExpanded (state) whether the TabRow elements are expanded

Review comment (bug):
Not a big fan of using the empty string here as a placeholder... it also looks like selecting is now broken for `People` and `Publication` as a related issue.

Code after:
        InterestScreenContent(currentSection, isExpandedScreen, onTabChange, tabContent, screenModifier)
    }
}

/**
 * Remembers the content for each tab on the Interests screen
 * gathering application data from [InterestsViewModel]
 */
@Composable
fun rememberTabContent(interestsViewModel: InterestsViewModel): List<TabContent> {
    // UiState of the InterestsScreen
    val uiState by interestsViewModel.uiState.collectAsState()

    // Describe the screen sections here since each section needs 2 states and 1 event.
    // Pass them to the stateless InterestsScreen using a tabContent.
    val topicsSection = TabContent(Sections.Topics) {
        val selectedTopics by interestsViewModel.selectedTopics.collectAsState()
        TabWithSections(
            sections = uiState.topics,
            selectedTopics = selectedTopics,
            onTopicSelect = { interestsViewModel.toggleTopicSelection(it) }
        )
    }

    val peopleSection = TabContent(Sections.People) {
        val selectedPeople by interestsViewModel.selectedPeople.collectAsState()
        TabWithTopics(
            topics = uiState.people,
            selectedTopics = selectedPeople,
            onTopicSelect = { interestsViewModel.togglePersonSelected(it) }
        )
    }

    val publicationSection = TabContent(Sections.Publications) {
        val selectedPublications by interestsViewModel.selectedPublications.collectAsState()
        TabWithTopics(
            topics = uiState.publications,
            selectedTopics = selectedPublications,
            onTopicSelect = { interestsViewModel.togglePublicationSelected(it) }
        )
    }

    return listOf(topicsSection, peopleSection, publicationSection)
}

/**
 * Displays a tab row with [currentSection] selected and the body of the corresponding [tabContent].
 *
 * @param currentSection (state) the tab that is currently selected
 * @param isExpandedScreen (state) whether or not the screen is expanded
 * @param updateSection (event) request a change in tab selection