Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into dependabot/gradle/ivy-wallet-45837ea364
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV authored Feb 14, 2024
2 parents 9588486 + 8f86f6e commit b78a32f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion screen/search/src/main/java/com/ivy/search/SearchScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private fun SearchUi(
val listState = rememberLazyListState()

var searchQueryTextFieldValue by remember {
mutableStateOf(selectEndTextFieldValue(""))
mutableStateOf(selectEndTextFieldValue(uiState.searchQuery))
}

SearchInput(
Expand Down Expand Up @@ -126,6 +126,7 @@ private fun Preview() {
IvyPreview {
SearchUi(
uiState = SearchState(
searchQuery = "Transaction",
transactions = persistentListOf(),
baseCurrency = "",
accounts = persistentListOf(),
Expand Down
1 change: 1 addition & 0 deletions screen/search/src/main/java/com/ivy/search/SearchState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.ivy.legacy.datamodel.Category
import kotlinx.collections.immutable.ImmutableList

data class SearchState(
val searchQuery: String,
val transactions: ImmutableList<TransactionHistoryItem>,
val baseCurrency: String,
val accounts: ImmutableList<Account>,
Expand Down
7 changes: 5 additions & 2 deletions screen/search/src/main/java/com/ivy/search/SearchViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ class SearchViewModel @Inject constructor(
private val baseCurrency = mutableStateOf<String>(getDefaultFIATCurrency().currencyCode)
private val accounts = mutableStateOf<ImmutableList<Account>>(persistentListOf())
private val categories = mutableStateOf<ImmutableList<Category>>(persistentListOf())
private val searchQuery = mutableStateOf("")

@Composable
override fun uiState(): SearchState {
LaunchedEffect(Unit) {
search("")
search(searchQuery.value)
}

return SearchState(
searchQuery = searchQuery.value,
transactions = transactions.value,
baseCurrency = baseCurrency.value,
accounts = accounts.value,
Expand All @@ -58,14 +60,15 @@ class SearchViewModel @Inject constructor(
}

private fun search(query: String) {
searchQuery.value = query
val normalizedQuery = query.lowercase().trim()

viewModelScope.launch {
val queryResult = ioThread {
val filteredTransactions = allTrnsAct(Unit)
.filter { transaction ->
transaction.title.matchesQuery(normalizedQuery) ||
transaction.description.matchesQuery(normalizedQuery)
transaction.description.matchesQuery(normalizedQuery)
}
trnsWithDateDivsAct(
TrnsWithDateDivsAct.Input(
Expand Down

0 comments on commit b78a32f

Please sign in to comment.