Skip to content

Commit 68c5d18

Browse files
authored
Merge pull request #48 from f-lab-edu/feature/refactor#47_search
refactor 검색 화면 구조 개선
2 parents 8950acd + ab3b89a commit 68c5d18

File tree

12 files changed

+546
-475
lines changed

12 files changed

+546
-475
lines changed

feature/search/src/main/java/com/chan/search/ui/composables/SearchFilterScreen.kt

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,33 @@ import androidx.compose.ui.unit.dp
2020
import com.chan.android.ui.theme.Spacing
2121
import com.chan.android.ui.theme.White
2222
import com.chan.search.R
23+
import com.chan.search.ui.contract.SearchContract
2324
import com.chan.search.ui.model.filter.DeliveryOption
2425
import com.chan.search.ui.model.filter.FilterCategoriesModel
2526

2627
@OptIn(ExperimentalMaterial3Api::class)
2728
@Composable
2829
fun SearchFilterScreen(
29-
selectedDeliveryOption: DeliveryOption?,
30-
categoryFilters: List<FilterCategoriesModel>,
31-
expandedCategoryName: String?,
32-
selectedSubCategories: Set<String>,
33-
isCategorySectionExpanded: Boolean,
34-
filteredProductCount: Int,
35-
onClose: () -> Unit,
36-
onDeliveryOptionClick: (DeliveryOption) -> Unit,
37-
onCategoryHeaderClick: (String) -> Unit,
38-
onSubCategoryClick: (String) -> Unit,
39-
onFilterCategoryClick: () -> Unit,
40-
onFilterClear: () -> Unit,
30+
state: SearchContract.State,
31+
onEvent: (SearchContract.Event) -> Unit,
4132
modifier: Modifier = Modifier
4233
) {
4334

4435
Scaffold(
4536
modifier = modifier,
4637
containerColor = White,
47-
topBar = { FilterHeader(
48-
onClose = onClose,
49-
onFilterClear = onFilterClear
50-
) },
51-
bottomBar = { FilterBottomButton(
52-
itemCount = filteredProductCount,
53-
onClick = onClose
54-
) }
38+
topBar = {
39+
FilterHeader(
40+
onClose = { onEvent(SearchContract.Event.Filter.OnFilterClick) },
41+
onFilterClear = { onEvent(SearchContract.Event.Filter.OnClear) }
42+
)
43+
},
44+
bottomBar = {
45+
FilterBottomButton(
46+
itemCount = state.filter.filteredProductCount,
47+
onApplyFilters = { onEvent(SearchContract.Event.Filter.OnFilterClick) }
48+
)
49+
}
5550
) { paddingValues ->
5651
LazyColumn(
5752
modifier = Modifier
@@ -60,8 +55,8 @@ fun SearchFilterScreen(
6055
// "오늘드림", "픽업" 체크박스 섹션
6156
item {
6257
FilterToggleSection(
63-
selectedOption = selectedDeliveryOption,
64-
onOptionClick = onDeliveryOptionClick
58+
selectedOption = state.filter.selectedDeliveryOption,
59+
onOptionClick = { onEvent(SearchContract.Event.Filter.OnDeliveryOptionChanged(it)) }
6560
)
6661
HorizontalDivider(
6762
color = Color.LightGray.copy(alpha = 0.2f),
@@ -75,21 +70,27 @@ fun SearchFilterScreen(
7570
//카테고리
7671
ExpandableFilterSection(
7772
title = stringResource(R.string.category_label),
78-
isExpanded = isCategorySectionExpanded,
79-
onClick = onFilterCategoryClick
73+
isExpanded = state.filter.isCategorySectionExpanded,
74+
onClick = { onEvent(SearchContract.Event.Filter.OnCategoryClick) }
8075
)
8176
HorizontalDivider(
8277
color = Color.LightGray.copy(alpha = 0.5f),
8378
thickness = 1.dp
8479
)
8580
//서브 카테고리
86-
if (isCategorySectionExpanded) {
81+
if (state.filter.isCategorySectionExpanded) {
8782
SubFilterCategory(
88-
categoryFilters = categoryFilters,
89-
expandedCategoryName = expandedCategoryName,
90-
selectedSubCategories = selectedSubCategories,
91-
onCategoryHeaderClick = onCategoryHeaderClick,
92-
onSubCategoryClick = onSubCategoryClick
83+
categoryFilters = state.filter.categoryFilters,
84+
expandedCategoryName = state.filter.expandedCategoryName,
85+
selectedSubCategories = state.filter.selectedSubCategories,
86+
onCategoryHeaderClick = {
87+
onEvent(
88+
SearchContract.Event.Filter.OnCategoryHeaderClick(
89+
it
90+
)
91+
)
92+
},
93+
onSubCategoryClick = { onEvent(SearchContract.Event.Filter.OnSubCategoryClick(it)) }
9394
)
9495
}
9596
}
@@ -103,7 +104,10 @@ fun SearchFilterScreen(
103104
}
104105

105106
item {
106-
ExpandableFilterSection(title = stringResource(R.string.product_view_mode_label), details = "2단")
107+
ExpandableFilterSection(
108+
title = stringResource(R.string.product_view_mode_label),
109+
details = "2단"
110+
)
107111
HorizontalDivider(
108112
color = Color.LightGray.copy(alpha = 0.5f),
109113
thickness = 1.dp
@@ -118,8 +122,8 @@ private fun SubFilterCategory(
118122
categoryFilters: List<FilterCategoriesModel>,
119123
expandedCategoryName: String?,
120124
selectedSubCategories: Set<String>,
121-
onCategoryHeaderClick: (String) -> Unit,
122-
onSubCategoryClick: (String) -> Unit,
125+
onCategoryHeaderClick: (categoryName: String) -> Unit,
126+
onSubCategoryClick: (subCategoryName: String) -> Unit,
123127
) {
124128
Column {
125129
categoryFilters.forEach { category ->
@@ -258,10 +262,10 @@ fun ExpandableFilterSection(
258262
@Composable
259263
fun FilterBottomButton(
260264
itemCount: Int,
261-
onClick: () -> Unit
265+
onApplyFilters: () -> Unit
262266
) {
263267
Button(
264-
onClick = onClick,
268+
onClick = onApplyFilters,
265269
modifier = Modifier
266270
.fillMaxWidth()
267271
.padding(Spacing.spacing4),
@@ -278,4 +282,8 @@ fun FilterBottomButton(
278282
fontWeight = FontWeight.Bold
279283
)
280284
}
281-
}
285+
}
286+
287+
288+
289+

feature/search/src/main/java/com/chan/search/ui/composables/SearchScreen.kt

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import androidx.compose.runtime.collectAsState
55
import androidx.compose.runtime.getValue
66
import androidx.hilt.navigation.compose.hiltViewModel
77
import androidx.navigation.NavHostController
8-
import com.chan.search.ui.contract.SearchContract
98
import com.chan.search.ui.viewmodel.SearchViewModel
109

1110
@Composable
@@ -17,39 +16,7 @@ fun SearchScreen(
1716

1817
SearchScreenContent(
1918
navController = navController,
20-
search = state.search,
21-
recentSearches = state.recentSearches,
22-
recommendedKeywords = state.recommendedKeywords,
23-
trendingSearches = state.trendingSearches,
24-
searchResults = state.searchResults,
25-
currentTime = state.currentTime,
26-
showSearchResult = state.showSearchResult,
27-
searchResultProducts = state.searchResultProducts,
28-
showFilter = state.showFilter,
29-
selectedDeliveryOption = state.selectedDeliveryOption,
30-
categoryFilters = state.categoryFilters,
31-
expandedCategoryName = state.expandedCategoryName,
32-
selectedSubCategories = state.selectedSubCategories,
33-
isCategorySectionExpanded = state.isCategorySectionExpanded,
34-
filteredProductCount = state.filteredProductCount,
35-
onSearchChanged = { viewModel.setEvent(SearchContract.Event.OnSearchChanged(it)) },
36-
onClearSearch = { viewModel.setEvent(SearchContract.Event.OnClickClearSearch) },
37-
onSearchClick = { viewModel.setEvent(SearchContract.Event.OnAddSearchKeyword(it)) },
38-
onSearchTextFocus = { viewModel.setEvent(SearchContract.Event.OnSearchTextFocus) },
39-
onRemoveSearchKeyword = { viewModel.setEvent(SearchContract.Event.OnRemoveSearchKeyword(it)) },
40-
onClearAllRecentSearches = { viewModel.setEvent(SearchContract.Event.OnClearAllRecentSearches) },
41-
onSearchResultItemClick = { viewModel.setEvent(SearchContract.Event.OnClickSearchProduct(it)) },
42-
onFilterClear = { viewModel.setEvent(SearchContract.Event.OnFilterClear) },
43-
onUpdateFilterClick = { viewModel.setEvent(SearchContract.Event.OnUpdateFilterClick) },
44-
onDeliveryOptionClick = { viewModel.setEvent(SearchContract.Event.OnDeliveryOptionChanged(it)) },
45-
onCategoryHeaderClick = { viewModel.setEvent(SearchContract.Event.OnCategoryHeaderClick(it)) },
46-
onSubCategoryClick = { viewModel.setEvent(SearchContract.Event.OnSubCategoryClick(it)) },
47-
onFilterCategoryClick = { viewModel.setEvent(SearchContract.Event.OnFilterCategoryClick) },
48-
onClickBack = {
49-
navController.popBackStack()
50-
},
51-
onClickCart = {
52-
// TODO : Cart 로 이동
53-
}
19+
state = state,
20+
onEvent = viewModel::setEvent
5421
)
5522
}

0 commit comments

Comments
 (0)