Skip to content

refactor 검색 화면 구조 개선 #48

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

Open
wants to merge 9 commits into
base: feature/feature#44_search
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,33 @@ import androidx.compose.ui.unit.dp
import com.chan.android.ui.theme.Spacing
import com.chan.android.ui.theme.White
import com.chan.search.R
import com.chan.search.ui.contract.SearchContract
import com.chan.search.ui.model.filter.DeliveryOption
import com.chan.search.ui.model.filter.FilterCategoriesModel

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SearchFilterScreen(
selectedDeliveryOption: DeliveryOption?,
categoryFilters: List<FilterCategoriesModel>,
expandedCategoryName: String?,
selectedSubCategories: Set<String>,
isCategorySectionExpanded: Boolean,
filteredProductCount: Int,
onClose: () -> Unit,
onDeliveryOptionClick: (DeliveryOption) -> Unit,
onCategoryHeaderClick: (String) -> Unit,
onSubCategoryClick: (String) -> Unit,
onFilterCategoryClick: () -> Unit,
onFilterClear: () -> Unit,
state: SearchContract.State,
onEvent: (SearchContract.Event) -> Unit,
modifier: Modifier = Modifier
) {

Scaffold(
modifier = modifier,
containerColor = White,
topBar = { FilterHeader(
onClose = onClose,
onFilterClear = onFilterClear
) },
bottomBar = { FilterBottomButton(
itemCount = filteredProductCount,
onClick = onClose
) }
topBar = {
FilterHeader(
onClose = { onEvent(SearchContract.Event.Filter.OnFilterClick) },
onFilterClear = { onEvent(SearchContract.Event.Filter.OnClear) }
)
},
bottomBar = {
FilterBottomButton(
itemCount = state.filter.filteredProductCount,
onApplyFilters = { onEvent(SearchContract.Event.Filter.OnFilterClick) }
)
}
) { paddingValues ->
LazyColumn(
modifier = Modifier
Expand All @@ -60,8 +55,8 @@ fun SearchFilterScreen(
// "오늘드림", "픽업" 체크박스 섹션
item {
FilterToggleSection(
selectedOption = selectedDeliveryOption,
onOptionClick = onDeliveryOptionClick
selectedOption = state.filter.selectedDeliveryOption,
onOptionClick = { onEvent(SearchContract.Event.Filter.OnDeliveryOptionChanged(it)) }
)
HorizontalDivider(
color = Color.LightGray.copy(alpha = 0.2f),
Expand All @@ -75,21 +70,27 @@ fun SearchFilterScreen(
//카테고리
ExpandableFilterSection(
title = stringResource(R.string.category_label),
isExpanded = isCategorySectionExpanded,
onClick = onFilterCategoryClick
isExpanded = state.filter.isCategorySectionExpanded,
onClick = { onEvent(SearchContract.Event.Filter.OnCategoryClick) }
)
HorizontalDivider(
color = Color.LightGray.copy(alpha = 0.5f),
thickness = 1.dp
)
//서브 카테고리
if (isCategorySectionExpanded) {
if (state.filter.isCategorySectionExpanded) {
SubFilterCategory(
categoryFilters = categoryFilters,
expandedCategoryName = expandedCategoryName,
selectedSubCategories = selectedSubCategories,
onCategoryHeaderClick = onCategoryHeaderClick,
onSubCategoryClick = onSubCategoryClick
categoryFilters = state.filter.categoryFilters,
expandedCategoryName = state.filter.expandedCategoryName,
selectedSubCategories = state.filter.selectedSubCategories,
onCategoryHeaderClick = {
onEvent(
SearchContract.Event.Filter.OnCategoryHeaderClick(
it
)
)
},
onSubCategoryClick = { onEvent(SearchContract.Event.Filter.OnSubCategoryClick(it)) }
)
}
}
Expand All @@ -103,7 +104,10 @@ fun SearchFilterScreen(
}

item {
ExpandableFilterSection(title = stringResource(R.string.product_view_mode_label), details = "2단")
ExpandableFilterSection(
title = stringResource(R.string.product_view_mode_label),
details = "2단"
)
HorizontalDivider(
color = Color.LightGray.copy(alpha = 0.5f),
thickness = 1.dp
Expand All @@ -118,8 +122,8 @@ private fun SubFilterCategory(
categoryFilters: List<FilterCategoriesModel>,
expandedCategoryName: String?,
selectedSubCategories: Set<String>,
onCategoryHeaderClick: (String) -> Unit,
onSubCategoryClick: (String) -> Unit,
onCategoryHeaderClick: (categoryName: String) -> Unit,
onSubCategoryClick: (subCategoryName: String) -> Unit,
) {
Column {
categoryFilters.forEach { category ->
Expand Down Expand Up @@ -258,10 +262,10 @@ fun ExpandableFilterSection(
@Composable
fun FilterBottomButton(
itemCount: Int,
onClick: () -> Unit
onApplyFilters: () -> Unit
) {
Button(
onClick = onClick,
onClick = onApplyFilters,
modifier = Modifier
.fillMaxWidth()
.padding(Spacing.spacing4),
Expand All @@ -278,4 +282,8 @@ fun FilterBottomButton(
fontWeight = FontWeight.Bold
)
}
}
}




Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import com.chan.search.ui.contract.SearchContract
import com.chan.search.ui.viewmodel.SearchViewModel

@Composable
Expand All @@ -17,39 +16,7 @@ fun SearchScreen(

SearchScreenContent(
navController = navController,
search = state.search,
recentSearches = state.recentSearches,
recommendedKeywords = state.recommendedKeywords,
trendingSearches = state.trendingSearches,
searchResults = state.searchResults,
currentTime = state.currentTime,
showSearchResult = state.showSearchResult,
searchResultProducts = state.searchResultProducts,
showFilter = state.showFilter,
selectedDeliveryOption = state.selectedDeliveryOption,
categoryFilters = state.categoryFilters,
expandedCategoryName = state.expandedCategoryName,
selectedSubCategories = state.selectedSubCategories,
isCategorySectionExpanded = state.isCategorySectionExpanded,
filteredProductCount = state.filteredProductCount,
onSearchChanged = { viewModel.setEvent(SearchContract.Event.OnSearchChanged(it)) },
onClearSearch = { viewModel.setEvent(SearchContract.Event.OnClickClearSearch) },
onSearchClick = { viewModel.setEvent(SearchContract.Event.OnAddSearchKeyword(it)) },
onSearchTextFocus = { viewModel.setEvent(SearchContract.Event.OnSearchTextFocus) },
onRemoveSearchKeyword = { viewModel.setEvent(SearchContract.Event.OnRemoveSearchKeyword(it)) },
onClearAllRecentSearches = { viewModel.setEvent(SearchContract.Event.OnClearAllRecentSearches) },
onSearchResultItemClick = { viewModel.setEvent(SearchContract.Event.OnClickSearchProduct(it)) },
onFilterClear = { viewModel.setEvent(SearchContract.Event.OnFilterClear) },
onUpdateFilterClick = { viewModel.setEvent(SearchContract.Event.OnUpdateFilterClick) },
onDeliveryOptionClick = { viewModel.setEvent(SearchContract.Event.OnDeliveryOptionChanged(it)) },
onCategoryHeaderClick = { viewModel.setEvent(SearchContract.Event.OnCategoryHeaderClick(it)) },
onSubCategoryClick = { viewModel.setEvent(SearchContract.Event.OnSubCategoryClick(it)) },
onFilterCategoryClick = { viewModel.setEvent(SearchContract.Event.OnFilterCategoryClick) },
onClickBack = {
navController.popBackStack()
},
onClickCart = {
// TODO : Cart 로 이동
}
state = state,
onEvent = viewModel::setEvent
)
}
Loading