diff --git a/core/src/main/java/com/terning/core/designsystem/component/textfield/SearchTextField.kt b/core/src/main/java/com/terning/core/designsystem/component/textfield/SearchTextField.kt index 1c4039b2c..79aab22a8 100644 --- a/core/src/main/java/com/terning/core/designsystem/component/textfield/SearchTextField.kt +++ b/core/src/main/java/com/terning/core/designsystem/component/textfield/SearchTextField.kt @@ -3,6 +3,8 @@ package com.terning.core.designsystem.component.textfield import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.text.input.ImeAction import com.terning.core.designsystem.theme.Grey300 import com.terning.core.designsystem.theme.Grey400 @@ -18,8 +20,11 @@ fun SearchTextField( leftIcon: Int, enabled: Boolean = true, readOnly: Boolean = false, - onDoneAction: (() -> Unit)? = null, + onSearchAction: () -> Unit? = {}, ) { + val keyboardController = LocalSoftwareKeyboardController.current + val focusManager = LocalFocusManager.current + TerningBasicTextField( value = text, onValueChange = onValueChange, @@ -33,14 +38,17 @@ fun SearchTextField( hintColor = Grey300, leftIcon = leftIcon, leftIconColor = TerningMain, - imeAction = if (text.isNotBlank()) { - ImeAction.Search - } else { - ImeAction.Done - }, + imeAction = ImeAction.Search, enabled = enabled, readOnly = readOnly, - onDoneAction = onDoneAction, + onSearchAction = { + if (text.isNotBlank()) { + keyboardController?.hide() + keyboardController?.hide() + focusManager.clearFocus() + onSearchAction() + } + }, helperColor = TerningMain ) } \ No newline at end of file diff --git a/core/src/main/java/com/terning/core/designsystem/component/textfield/TerningBasicTextField.kt b/core/src/main/java/com/terning/core/designsystem/component/textfield/TerningBasicTextField.kt index 49cb64610..fd3bab05d 100644 --- a/core/src/main/java/com/terning/core/designsystem/component/textfield/TerningBasicTextField.kt +++ b/core/src/main/java/com/terning/core/designsystem/component/textfield/TerningBasicTextField.kt @@ -22,8 +22,6 @@ import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalFocusManager -import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.input.ImeAction @@ -46,7 +44,7 @@ fun TerningBasicTextField( strokeWidth: Float = 1f, leftIcon: Int? = null, leftIconColor: Color = TerningMain, - imeAction: ImeAction? = ImeAction.Done, + imeAction: ImeAction = ImeAction.Done, maxTextLength: Int? = null, showTextLength: Boolean = false, hint: String = "", @@ -55,30 +53,24 @@ fun TerningBasicTextField( enabled: Boolean = true, helperColor: Color, readOnly: Boolean = false, - onDoneAction: (() -> Unit)? = null, + onDoneAction: () -> Unit? = {}, + onSearchAction: () -> Unit? = {}, ) { - val keyboardController = LocalSoftwareKeyboardController.current - val focusManager = LocalFocusManager.current val isFocused: MutableState = remember { mutableStateOf(false) } BasicTextField( value = value, - onValueChange = onValueChange, + onValueChange = { + if (maxTextLength == null || it.length <= maxTextLength) { + onValueChange(it) + } + }, singleLine = true, maxLines = 1, - keyboardOptions = KeyboardOptions( - imeAction = imeAction ?: ImeAction.Done - ), + keyboardOptions = KeyboardOptions(imeAction = imeAction), keyboardActions = KeyboardActions( - onDone = { - if (value.isNotBlank()) { - keyboardController?.hide() - focusManager.clearFocus() - if (onDoneAction != null) { - onDoneAction() - } - } - } + onDone = { onDoneAction() }, + onSearch = { onSearchAction() }, ), modifier = modifier diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt index 544fd9c92..580ed6c9f 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt @@ -99,7 +99,7 @@ fun HomeRoute( } } - LaunchedEffect(currentSortBy.value) { + LaunchedEffect(homeFilteringState, currentSortBy.value) { when (homeFilteringState) { is UiState.Success -> with((homeFilteringState as UiState.Success).data) { diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index 36dc99c51..23c813f3e 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -53,11 +53,6 @@ class HomeViewModel @Inject constructor( getProfile() getFilteringInfo() getHomeTodayInternList() - getRecommendInternsData( - sortBy = _homeSortByState.value, - startYear = 2024, - startMonth = 8, - ) } fun getRecommendInternsData(sortBy: Int, startYear: Int, startMonth: Int) { diff --git a/feature/src/main/java/com/terning/feature/search/searchprocess/SearchProcessRoute.kt b/feature/src/main/java/com/terning/feature/search/searchprocess/SearchProcessRoute.kt index 7a5526ee2..181751438 100644 --- a/feature/src/main/java/com/terning/feature/search/searchprocess/SearchProcessRoute.kt +++ b/feature/src/main/java/com/terning/feature/search/searchprocess/SearchProcessRoute.kt @@ -146,7 +146,7 @@ fun SearchProcessScreen( .padding(top = 8.dp) .focusRequester(focusRequester) .addFocusCleaner(focusManager), - onDoneAction = { + onSearchAction = { viewModel.getSearchList( keyword = state.text, sortBy = SORT_BY,