Skip to content

Instantly share code, notes, and snippets.

@Aldikitta
Created June 14, 2023 10:01
Show Gist options
  • Save Aldikitta/3a6153c39784eaab8068fc1df0527065 to your computer and use it in GitHub Desktop.
Save Aldikitta/3a6153c39784eaab8068fc1df0527065 to your computer and use it in GitHub Desktop.
val visitId = savedStateHandle.get<Int>("visitId")
val agentDetail: StateFlow<VisitingDetailUiState>? =
visitId?.let {
useCase.getDetailAgentVisitFullResponseFlow(id = it).map { visitDetail ->
Log.d("MYTAG", ": got exec")
when (visitDetail) {
is SallyResponseResource.Loading -> {
VisitingDetailUiState.Loading
}
is SallyResponseResource.Success -> {
VisitingDetailUiState.Success(visitDetail.data.data)
}
is SallyResponseResource.Error -> {
_eventFlow.emit(
VisitingUiEvent.ShowErrorMessageStatic(
staticError = visitDetail.exception.message,
dynamicError = visitDetail.exception.cause?.message.toString(),
errorCode = visitDetail.errorCode
)
)
VisitingDetailUiState.Error(error = visitDetail.exception.toString())
}
}
}.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5_000),
VisitingDetailUiState.Loading
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment