Skip to content

Commit

Permalink
fix(home): fix blinking huge error on home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
rhenwinch committed Sep 30, 2024
1 parent c4459b4 commit ab437cc
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ import com.flixclusive.model.provider.Catalog
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -98,22 +95,18 @@ class HomeScreenViewModel @Inject constructor(

init {
viewModelScope.launch {
val initializationStatus = homeItemsProviderUseCase.state.map {
it.status
}.distinctUntilChanged()

connectionObserver
.combine(initializationStatus) { isConnected, status ->
isConnected to status
}
.onEach { (isConnected, status) ->
.collectLatest { isConnected ->
val status = homeItemsProviderUseCase.state.map {
it.status
}.first()

if (isConnected && status is Resource.Failure || status is Resource.Loading) {
initialize()
} else if(status is Resource.Success) {
onPaginateCatalogs()
}
}
.collect()
}
}

Expand Down

0 comments on commit ab437cc

Please sign in to comment.