Skip to content

Commit

Permalink
feat(ChildCommentViewModel): 새로고침 시엔 네트워크 에러에 의해 새로고침 할 수 없어도 네트워크 화면…
Browse files Browse the repository at this point in the history
…을 보여주지 않도록 변경
  • Loading branch information
ki960213 committed Nov 1, 2023
1 parent 41853fe commit a81e667
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ abstract class BaseViewModel : ViewModel() {
onSuccess: ((T) -> Unit)? = null,
onFailure: ((code: Int, message: String?) -> Unit)? = null,
onLoading: (suspend () -> Unit)? = null,
onNetworkError: (() -> Unit)? = null,
): Job = viewModelScope.launch {
val loadingJob = launch { onLoading?.invoke() ?: changeToLoadingState() }
when (val result = getResult()) {
is Failure -> onFailure?.invoke(result.code, result.message)
NetworkError -> {
changeToNetworkErrorState()
onNetworkError?.invoke() ?: changeToNetworkErrorState()
return@launch
}

Expand All @@ -50,11 +51,12 @@ abstract class BaseViewModel : ViewModel() {
onSuccess: ((T) -> Unit)? = null,
onFailure: ((code: Int, message: String?) -> Unit)? = null,
onLoading: (suspend () -> Unit)? = null,
onNetworkError: (() -> Unit)? = null,
): Job = viewModelScope.launch {
val loadingJob = launch { onLoading?.invoke() ?: changeToLoadingState() }
when (val result = command()) {
is Failure -> onFailure?.invoke(result.code, result.message)
NetworkError -> onRequestFailByNetworkError()
NetworkError -> onNetworkError?.invoke() ?: onRequestFailByNetworkError()
is Success -> {
refresh().join()
onSuccess?.invoke(result.data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class ChildCommentViewModel @Inject constructor(
onSuccess = { _comments.value = ChildCommentsUiState.create(uid, parentComment = it) },
onFailure = { _, _ -> },
onLoading = {},
onNetworkError = ::onRequestFailByNetworkError,
)

override fun changeToLoadingState() {
Expand Down

0 comments on commit a81e667

Please sign in to comment.