Skip to content

Commit

Permalink
[FEAT/#218] 함수 합치기
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Sep 7, 2024
1 parent e410bb5 commit 278d274
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ fun FilteringOneRoute(
FilteringOneScreen(
name = name,
onButtonClick = { index ->
viewModel.updateGrade(index)
viewModel.updateButtonValidation()
viewModel.updateGradeAndButton(index)
},
onNextClick = onNextClick,
navigateUp = viewModel::navigateUp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ class FilteringOneViewModel : ViewModel() {
private val _sideEffects = MutableSharedFlow<FilteringOneSideEffect>()
val sideEffects: SharedFlow<FilteringOneSideEffect> get() = _sideEffects.asSharedFlow()

fun updateButtonValidation() {
_state.value = _state.value.copy(isButtonValid = true)
}

fun updateGrade(grade: Int) {
_state.value = _state.value.copy(grade = grade)
fun updateGradeAndButton(grade: Int) {
_state.value = _state.value.copy(
grade = grade,
isButtonValid = true
)
}

fun navigateUp() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ fun FilteringTwoRoute(
onNextClick = onNextClick,
navigateUp = viewModel::navigateUp,
onButtonClick = { index ->
viewModel.updateWorkingPeriod(index)
viewModel.updateButtonValidation()
viewModel.updateWorkingPeriodAndButton(index)
},
buttonState = state.isButtonValid,
workingPeriod = state.workingPeriod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.terning.feature.filtering.filteringtwo

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.terning.feature.filtering.filteringone.FilteringOneSideEffect
import com.terning.feature.filtering.filteringone.FilteringOneState
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
Expand All @@ -12,20 +10,19 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch

class FilteringTwoViewModel : ViewModel(){
class FilteringTwoViewModel : ViewModel() {

private val _state: MutableStateFlow<FilteringTwoState> = MutableStateFlow(FilteringTwoState())
val state: StateFlow<FilteringTwoState> get() = _state.asStateFlow()

private val _sideEffects = MutableSharedFlow<FilteringTwoSideEffect>()
val sideEffects: SharedFlow<FilteringTwoSideEffect> get() = _sideEffects.asSharedFlow()

fun updateButtonValidation() {
_state.value = _state.value.copy(isButtonValid = true)
}

fun updateWorkingPeriod(workingPeriod: Int) {
_state.value = _state.value.copy(workingPeriod = workingPeriod)
fun updateWorkingPeriodAndButton(workingPeriod: Int) {
_state.value = _state.value.copy(
workingPeriod = workingPeriod,
isButtonValid = true
)
}

fun navigateUp() =
Expand Down

0 comments on commit 278d274

Please sign in to comment.