Skip to content

Commit

Permalink
[feat/validate_for_register]: 식당 등록 시 필수 항목들 입력 여부 검증 후 버튼 enable처리
Browse files Browse the repository at this point in the history
  • Loading branch information
soopeach committed Sep 9, 2023
1 parent 244b19c commit ce3a0ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.chip.Chip
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import okhttp3.MediaType
import okhttp3.MultipartBody
Expand Down Expand Up @@ -267,6 +268,12 @@ class RegisterRestaurantFragment : BaseFragment() {
}
}
}

repeatWhenUiStarted {
viewModel.canRegisterState.collectLatest {
binding.registerButton.isEnabled = it
}
}
}

private fun setFoodCategoryContainer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -77,6 +78,20 @@ class RegisterRestaurantViewModel @Inject constructor(
MutableStateFlow(emptyArray())
val isFoodImagesListState = _isFoodImagesListState.asStateFlow()

val canRegisterState: StateFlow<Boolean>
get() = combine(
foodCategoryState,
introductionTextState,
recommendMenuListState
) { foodCategoryState, introductionState, recommendMenuListState ->
foodCategoryState != FoodCategoryItem.INIT && introductionState.isNotBlank() && recommendMenuListState.isNotEmpty()
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = false
)


fun setFoodImagesListState(list: Array<String>) {
_isFoodImagesListState.value = list
}
Expand Down Expand Up @@ -188,7 +203,7 @@ class RegisterRestaurantViewModel @Inject constructor(
},
categoryId = foodCategoryState.value.categoryItem.id.toInt(),
id = restaurantId,
)
)
)
}
}
Expand Down

0 comments on commit ce3a0ab

Please sign in to comment.