Skip to content

Commit

Permalink
#308 [fix] 저장 가능, 대표 룰 수정 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
murjune committed Sep 3, 2023
1 parent 190a1b6 commit 88980e5
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class RepresentRuleViewModel @Inject constructor(
}
}

val isSavable get() = uiState.value.rules == uiState.value.originRules
val isSavable get() = uiState.value.rules != uiState.value.originRules

fun updateRuleBy(id: Int) {
viewModelScope.launch {
if (canAddRepresentRule()) {
if (canUpdateRuleBy(id)) {
uiEvents.send(RepresentRulesEvent.UpdateRule(id))
return@launch
}
Expand Down Expand Up @@ -78,8 +78,10 @@ class RepresentRuleViewModel @Inject constructor(
}
}

private fun canAddRepresentRule(): Boolean {
return uiState.value.rules.filter { it.isRepresent }.size < 3
private fun canUpdateRuleBy(id: Int): Boolean {
val isRepresent = uiState.value.rules.find { it.id == id }?.isRepresent ?: false
if (isRepresent) return true
return uiState.value.rules.count { it.isRepresent } + 1 <= 3
}

private companion object {
Expand Down

0 comments on commit 88980e5

Please sign in to comment.