Skip to content

Commit

Permalink
체크아이템 체크 속도 느린 현상 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
leesa-l committed Dec 23, 2023
1 parent cf6c9f8 commit 5e376ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.dkin.chevit.presentation.checklist.detail

import androidx.lifecycle.viewModelScope
import com.dkin.chevit.core.mvi.MVIViewModel
import com.dkin.chevit.domain.base.get
import com.dkin.chevit.domain.base.onComplete
import com.dkin.chevit.domain.model.CheckItem
import com.dkin.chevit.domain.usecase.plan.DeleteCheckItemUseCase
import com.dkin.chevit.domain.usecase.plan.GetCategoryUseCase
import com.dkin.chevit.domain.usecase.plan.PostNewCheckItemUseCase
Expand Down Expand Up @@ -120,20 +122,38 @@ class ChecklistDetailViewModel @Inject constructor(
checkItem.onComplete(
doOnComplete = {},
doOnError = {
if (it is NullPointerException) {
//성공했을 때 응답값이 null로 내려옴
getChecklistDetail(currentState.planId, currentState.categoryId)
} else {
setEffect { ChecklistDetailEffect.CheckItemFailed }
}
setEffect { ChecklistDetailEffect.CheckItemFailed }
},
doOnSuccess = {
getChecklistDetail(currentState.planId, currentState.categoryId)
val res = checkItem.get()
updateCheckItem(res)
}
)
}
}

private fun updateCheckItem(item: CheckItem) {
setState {
val currentState = state.value
if (currentState is ChecklistDetailState.Available) {
val updated = currentState.detailItems.map {
if (it.id == item.id) ChecklistDetailState.Available.ChecklistDetailItem(
id = item.id,
checked = item.checked,
title = item.content,
memo = item.memo,
count = item.quantity
) else it
}
currentState.copy(
detailItems = updated
)
} else {
currentState
}
}
}

private suspend fun removeItem(itemId: String) {
val currentState = state.value
if (currentState is ChecklistDetailState.Available) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ private fun HomeLoading(
.fillMaxWidth()
.padding(horizontal = 24.dp)
.weight(1f),

) {
Text(
text = "나의 체크리스트",
Expand Down

0 comments on commit 5e376ec

Please sign in to comment.