Skip to content

Commit

Permalink
[FEATURE]#74 : 차단 해제 버튼 클릭시 버튼 disabled 후 API 호출하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Aug 4, 2024
1 parent 76d05f9 commit 69b74f4
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class EntireViewModel @Inject constructor(
EntireAction.OnSignOutButtonClicked -> signOut()
EntireAction.OnRevokeConfirmed -> handleRevokeConfirmed()
EntireAction.OnBlockListScreenEntered -> getUnBlockedMessage()
EntireAction.UnBlockMessage -> unblockMessage()
is EntireAction.OnUnBlockButtonClicked -> handleUnBlockButtonClicked(action.messageId)
is EntireAction.OnRevokeReasonSelected -> handleRevokeReasonSelected(action.reason)
is EntireAction.UnBlockMessage -> unblockMessage(action.messageId)
}
}

Expand Down Expand Up @@ -84,19 +85,28 @@ class EntireViewModel @Inject constructor(
}
}

private fun unblockMessage(messageId: Int) = intent {
private fun handleUnBlockButtonClicked(messageId: Int) = intent {
reduce { state.copy(unBlockMessageId = messageId) }
}

private fun unblockMessage() = intent {
val messageId = state.unBlockMessageId
if (state.unBlockList.contains(messageId).not()) {
val updatedList = state.unBlockList.toMutableList().apply { add(messageId) }
reduce { state.copy(unBlockList = updatedList) }
}

viewModelScope.launch {
messageStorageRepository.blockMessage(messageId)
.onSuccess {
val updatedList = state.unBlockList.toMutableList().apply {
if (contains(messageId).not()) {
add(messageId)
}
}
reduce { state.copy(unBlockList = updatedList) }
}
.onFailure {
Timber.e(it)
// 차단 해제 실패 시, 차단 해제된 목록에서 삭제
if (state.unBlockList.contains(messageId)) {
val updatedList = state.unBlockList.toMutableList().apply {
remove(messageId)
}
reduce { state.copy(unBlockList = updatedList) }
}
}
}
}
Expand Down

0 comments on commit 69b74f4

Please sign in to comment.