We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MusicSearch/shared/feature/collections/src/commonMain/kotlin/ly/david/musicsearch/shared/feature/collections/add/AddToCollectionPresenter.kt
Line 26 in 65f0ce5
package ly.david.musicsearch.shared.feature.collections.add import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope import app.cash.paging.compose.LazyPagingItems import app.cash.paging.compose.collectAsLazyPagingItems import com.slack.circuit.runtime.Navigator import com.slack.circuit.runtime.presenter.Presenter import kotlinx.coroutines.launch import ly.david.musicsearch.core.models.listitem.CollectionListItemModel import ly.david.musicsearch.domain.collection.CollectionRepository import ly.david.musicsearch.domain.collection.usecase.CreateCollection import ly.david.musicsearch.domain.collection.usecase.GetAllCollections import ly.david.ui.common.screen.AddToCollectionScreen internal class AddToCollectionPresenter( private val screen: AddToCollectionScreen, private val navigator: Navigator, private val getAllCollections: GetAllCollections, private val createCollection: CreateCollection, private val collectionRepository: CollectionRepository, ) : Presenter<AddToCollectionUiState> { @Composable override fun present(): AddToCollectionUiState { val scope = rememberCoroutineScope() // TODO: show remote based on whether user is logged in val lazyPagingItems: LazyPagingItems<CollectionListItemModel> = getAllCollections( showLocal = true, showRemote = true, entity = screen.entity, ).collectAsLazyPagingItems() fun eventSink(event: AddToCollectionUiEvent) { when (event) { is AddToCollectionUiEvent.CreateCollection -> { val name = event.newCollection.name ?: return val entity = event.newCollection.entity ?: return createCollection( name = name, entity = entity, ) } is AddToCollectionUiEvent.AddToCollection -> { scope.launch { collectionRepository.addToCollection( collectionId = event.id, entity = screen.entity, entityId = screen.id, ) navigator.pop() } } } } return AddToCollectionUiState( lazyPagingItems = lazyPagingItems, eventSink = ::eventSink, ) } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
MusicSearch/shared/feature/collections/src/commonMain/kotlin/ly/david/musicsearch/shared/feature/collections/add/AddToCollectionPresenter.kt
Line 26 in 65f0ce5
The text was updated successfully, but these errors were encountered: