Skip to content

Commit

Permalink
Merge pull request #313 from team-peekabook/feature/#312-fix-recommen…
Browse files Browse the repository at this point in the history
…d-null-bug

#312 [fix] 추천책 없을 때 터지는 버그 수정
  • Loading branch information
2zerozu authored Mar 22, 2024
2 parents e26625a + a780234 commit 90e17e9
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class RecommendViewModel @Inject constructor(
private val _isEditMode = MediatorLiveData<Boolean>().apply {
value = false

addSource(_recommendedBook) {
value = checkEditMode(it, requireNotNull(_recommendingBook.value))
addSource(_recommendedBook) { recommendedBooks ->
value = checkEditMode(recommendedBooks, _recommendingBook.value ?: emptyList())
}
addSource(_recommendingBook) {
value = checkEditMode(requireNotNull(_recommendedBook.value), it)
addSource(_recommendingBook) { recommendingBooks ->
value = checkEditMode(_recommendedBook.value ?: emptyList(), recommendingBooks)
}
}
val isEditMode: LiveData<Boolean> = _isEditMode
Expand All @@ -57,14 +57,14 @@ class RecommendViewModel @Inject constructor(
}

fun toggleEditMode() {
_isEditMode.value = requireNotNull(_isEditMode.value).not()
_isEditMode.value = _isEditMode.value?.not() ?: false
val updatedRecommendedBooks =
_recommendedBook.value?.map { it.copy(isEditMode = requireNotNull(_isEditMode.value)) }
_recommendedBook.value = requireNotNull(updatedRecommendedBooks)
_recommendedBook.value?.map { it.copy(isEditMode = _isEditMode.value ?: false) }
_recommendedBook.value = updatedRecommendedBooks ?: emptyList()

val updatedRecommendingBooks =
_recommendingBook.value?.map { it.copy(isEditMode = requireNotNull(_isEditMode.value)) }
_recommendingBook.value = requireNotNull(updatedRecommendingBooks)
_recommendingBook.value?.map { it.copy(isEditMode = _isEditMode.value ?: false) }
_recommendingBook.value = updatedRecommendingBooks ?: emptyList()
}

fun deleteRecommend() {
Expand Down

0 comments on commit 90e17e9

Please sign in to comment.