-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mod] 필터뷰 슈정 #221
[mod] 필터뷰 슈정 #221
Changes from all commits
cebc374
532c91b
f6c330a
4a04a48
8f5aa8d
c1e2e68
16e2169
a7889dd
e95064a
ed1d8c3
31488ba
acd3c8e
c8bcfa8
58028ed
e06d3c0
ec2f607
7ce74e0
6336c2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import com.sopt.geonppang.domain.repository.FilterSettingRepository | |
import com.sopt.geonppang.presentation.model.AmplitudeFilterSettingInfo | ||
import com.sopt.geonppang.presentation.type.BreadFilterType | ||
import com.sopt.geonppang.presentation.type.FilterInfoType | ||
import com.sopt.geonppang.presentation.type.MainPurposeType | ||
import com.sopt.geonppang.presentation.type.MainPurposeFilterType | ||
import com.sopt.geonppang.presentation.type.NutrientFilterType | ||
import com.sopt.geonppang.presentation.type.UserRoleType | ||
import com.sopt.geonppang.util.UiState | ||
|
@@ -34,33 +34,21 @@ class FilterSettingViewModel @Inject constructor( | |
val previousActivity get() = _previousActivity.asStateFlow() | ||
private val _currentPage = MutableStateFlow<Int?>(null) | ||
val currentPage get() = _currentPage.asStateFlow() | ||
private val _mainPurposeType = MutableStateFlow<MainPurposeType?>(null) | ||
private val _mainPurposeType = MutableStateFlow<MainPurposeFilterType?>(null) | ||
val mainPurposeType get() = _mainPurposeType.asStateFlow() | ||
val breadFilterType: MutableStateFlow<Map<BreadFilterType, Boolean>> = MutableStateFlow( | ||
mapOf( | ||
BreadFilterType.GLUTENFREE to false, | ||
BreadFilterType.VEGAN to false, | ||
BreadFilterType.NUTFREE to false, | ||
BreadFilterType.SUGARFREE to false | ||
) | ||
) | ||
val nutrientFilterType: MutableStateFlow<Map<NutrientFilterType, Boolean>> = MutableStateFlow( | ||
mapOf( | ||
NutrientFilterType.NUTRIENT to false, | ||
NutrientFilterType.INGREDIENT to false, | ||
NutrientFilterType.NOT to false | ||
) | ||
) | ||
val breadFilterTypeList: MutableStateFlow<List<Int>> = MutableStateFlow(emptyList()) | ||
private val _nutrientFilterType = MutableStateFlow<NutrientFilterType?>(null) | ||
val nutrientFilterType get() = _nutrientFilterType.asStateFlow() | ||
val isFilterBtnEnabled: StateFlow<Boolean> = combine( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. combine을 사용하지 않고 이를 해결할 수 있는 방법은 없는지 알아봐도 좋을 거 같아영 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여러 개의 flow를 한 번에 관찰해야 하는 경우에 combine, zip, merge 등등 여러 방법을 사용할 수 있지만, 지금처럼 여러 개의 flow를 관찰하고 결과를 내야 하는 경우에는 combine을 사용하는 방법이 제일 적합할 것 같다는 생각이 듭니다요,,! 다른 좋은 방법이 있을까염? |
||
currentPage, | ||
mainPurposeType, | ||
breadFilterType, | ||
breadFilterTypeList, | ||
nutrientFilterType | ||
) { currentPage, mainPurposeType, breadFilterType, nutrientFilterType -> | ||
when (currentPage) { | ||
0 -> mainPurposeType != null | ||
1 -> breadFilterType.any { it.value } | ||
2 -> nutrientFilterType.any { it.value } | ||
1 -> breadFilterType.isNotEmpty() | ||
2 -> nutrientFilterType != null | ||
else -> false | ||
} | ||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false) | ||
|
@@ -75,52 +63,42 @@ class FilterSettingViewModel @Inject constructor( | |
_currentPage.value = position | ||
} | ||
|
||
fun setMainPurposeType(mainPurposeType: MainPurposeType) { | ||
fun setMainPurposeType(mainPurposeType: MainPurposeFilterType) { | ||
_mainPurposeType.value = mainPurposeType | ||
} | ||
|
||
fun setBreadFilterType(breadType: BreadFilterType) { | ||
val isSelected = breadFilterType.value[breadType] ?: return | ||
breadFilterType.value = breadFilterType.value.toMutableMap().apply { | ||
this[breadType] = !isSelected | ||
breadFilterTypeList.value = breadFilterTypeList.value.toMutableList().apply { | ||
if (!remove(breadType.id)) add(breadType.id) | ||
sort() | ||
} | ||
} | ||
|
||
fun setNutrientFilterType(nutrientType: NutrientFilterType) { | ||
val isSelected = nutrientFilterType.value[nutrientType] ?: return | ||
nutrientFilterType.value = nutrientFilterType.value.toMutableMap().apply { | ||
this[nutrientType] = !isSelected | ||
} | ||
_nutrientFilterType.value = nutrientType | ||
} | ||
|
||
fun setUserFilter() { | ||
viewModelScope.launch { | ||
_mainPurposeType.value?.let { | ||
RequestSettingFilter( | ||
it.name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지금보니 이게 뭐람 |
||
RequestSettingFilter.BreadType( | ||
breadFilterType.value[BreadFilterType.GLUTENFREE] == true, | ||
breadFilterType.value[BreadFilterType.VEGAN] == true, | ||
breadFilterType.value[BreadFilterType.NUTFREE] == true, | ||
breadFilterType.value[BreadFilterType.SUGARFREE] == true, | ||
), | ||
RequestSettingFilter.NutrientType( | ||
nutrientFilterType.value[NutrientFilterType.NUTRIENT] == true, | ||
nutrientFilterType.value[NutrientFilterType.INGREDIENT] == true, | ||
nutrientFilterType.value[NutrientFilterType.NOT] == true, | ||
_mainPurposeType.value?.let { mainPurposeFilterType -> | ||
_nutrientFilterType.value?.let { nutrientFilterType -> | ||
RequestSettingFilter( | ||
mainPurpose = mainPurposeFilterType.name, | ||
breadTypeList = breadFilterTypeList.value, | ||
nutrientTypeList = listOf(nutrientFilterType.id) | ||
) | ||
) | ||
}?.let { | ||
filterRepository.setUserFilter( | ||
it | ||
) | ||
// 필터를 선택한 경우 | ||
} | ||
}?.let { requestSettingFilter -> | ||
filterRepository.setUserFilter(requestSettingFilter) | ||
.onSuccess { | ||
_selectedFilterState.value = UiState.Success( | ||
AmplitudeFilterSettingInfo( | ||
mainPurposeType = _mainPurposeType.value, | ||
breadType = breadFilterType.value, | ||
ingredientType = nutrientFilterType.value, | ||
breadType = breadFilterTypeList.value.mapNotNull { breadFilterTypeId -> | ||
BreadFilterType.values() | ||
.find { it.id == breadFilterTypeId }?.name | ||
}, | ||
ingredientType = _nutrientFilterType.value, | ||
) | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
package com.sopt.geonppang.presentation.model | ||
|
||
import com.sopt.geonppang.presentation.type.BreadFilterType | ||
import com.sopt.geonppang.presentation.type.MainPurposeType | ||
import com.sopt.geonppang.presentation.type.MainPurposeFilterType | ||
import com.sopt.geonppang.presentation.type.NutrientFilterType | ||
|
||
data class AmplitudeFilterSettingInfo( | ||
val mainPurposeType: MainPurposeType?, | ||
val breadType: Map<BreadFilterType, Boolean>, | ||
val ingredientType: Map<NutrientFilterType, Boolean> | ||
val mainPurposeType: MainPurposeFilterType?, | ||
val breadType: List<String>, | ||
val ingredientType: NutrientFilterType? | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금 보니 flow가 정말 많이 사용됐다는 느낌이 드는거 같아욤 flow를 유사한 거 까리 뭉텅이로 같이 사용하는 방식으로 해도 좋을 거 같습니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고민해보겠습니다요,,,