@VisibleForTesting internal fun restoreSelectedCategories( coroutineScope: CoroutineScope, currentCategories: List<PocketRecommendedStoriesCategory>, store: Store<AppState, AppAction>, selectedPocketCategoriesDataStore: DataStore<SelectedPocketStoriesCategories>, ) { coroutineScope.launch { store.dispatch( AppAction.PocketStoriesCategoriesSelectionsChange( currentCategories, selectedPocketCategoriesDataStore.data.first() .valuesList.map { PocketRecommendedStoriesSelectedCategory( name = it.name, selectionTimestamp = it.selectionTimestamp, ) }, ), ) } }
Combines [currentCategories] with the locally persisted data about previously selected categories and emits a new [AppAction.PocketStoriesCategoriesSelectionsChange] to update these in store.