Skip to content

Commit 892c347

Browse files
committed
refactor(search, apps): improve state management and UI consistency
This commit refines the search logic, enhances the filtering mechanism in the apps feature, and cleans up UI-related imports and annotations. - **feat(search)**: Updated `OnClearClick` action to reset repositories, loading states, and error messages in addition to clearing the query. - **fix(search)**: Corrected `totalCount` calculation in `SearchViewModel` to ensure it reflects the actual size of the updated repository list. - **feat(apps)**: Optimized `filterApps` by extracting the filtering logic into `computeFilteredApps` and ensured the filtered list is updated when app status or progress changes. - **refactor(apps)**: Fixed `ExpressiveCard` modifier application in `AppCard` to ensure correct layout behavior. - **refactor(search)**: Cleaned up unused imports and `OptIn` annotations for `ExperimentalMaterial3Api` and `ExperimentalFoundationApi`. - **chore**: Replaced wildcard imports with explicit imports in `SearchRoot.kt` for better clarity.
1 parent 97c7155 commit 892c347

4 files changed

Lines changed: 34 additions & 24 deletions

File tree

feature/apps/presentation/src/commonMain/kotlin/zed/rainxch/apps/presentation/AppsRoot.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ fun AppItemCard(
374374
) {
375375
val app = appItem.installedApp
376376

377-
ExpressiveCard {
377+
ExpressiveCard (modifier = modifier) {
378378
Column(
379-
modifier = modifier
379+
modifier = Modifier
380380
.clip(RoundedCornerShape(32.dp))
381381
.clickable { onRepoClick() }
382382
.padding(16.dp)

feature/apps/presentation/src/commonMain/kotlin/zed/rainxch/apps/presentation/AppsViewModel.kt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,27 +208,25 @@ class AppsViewModel(
208208
}
209209

210210
private fun filterApps() {
211-
_state.update {
212-
it.copy(
213-
filteredApps = if (_state.value.searchQuery.isBlank()) {
214-
_state.value.apps.sortedBy { it.installedApp.isUpdateAvailable }
215-
} else {
216-
_state.value.apps.filter { appItem ->
217-
appItem.installedApp.appName.contains(
218-
_state.value.searchQuery,
219-
ignoreCase = true
220-
) ||
221-
appItem.installedApp.repoOwner.contains(
222-
_state.value.searchQuery,
223-
ignoreCase = true
224-
)
225-
}.sortedBy { it.installedApp.isUpdateAvailable }
226-
}
211+
_state.update { current ->
212+
current.copy(
213+
filteredApps = computeFilteredApps(current.apps, current.searchQuery)
227214
)
228215
}
216+
}
229217

218+
private fun computeFilteredApps(apps: List<AppItem>, query: String): List<AppItem> {
219+
return if (query.isBlank()) {
220+
apps.sortedBy { it.installedApp.isUpdateAvailable }
221+
} else {
222+
apps.filter { appItem ->
223+
appItem.installedApp.appName.contains(query, ignoreCase = true) ||
224+
appItem.installedApp.repoOwner.contains(query, ignoreCase = true)
225+
}.sortedBy { it.installedApp.isUpdateAvailable }
226+
}
230227
}
231228

229+
232230
private fun uninstallApp(app: InstalledApp) {
233231
viewModelScope.launch {
234232
try {
@@ -566,6 +564,8 @@ class AppsViewModel(
566564
}
567565
)
568566
}
567+
568+
filterApps()
569569
}
570570

571571
private fun updateAppProgress(packageName: String, progress: Int?) {
@@ -580,6 +580,8 @@ class AppsViewModel(
580580
}
581581
)
582582
}
583+
584+
filterApps()
583585
}
584586

585587
private suspend fun markPendingUpdate(app: InstalledApp) {

feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchRoot.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package zed.rainxch.search.presentation
22

3-
import androidx.compose.foundation.ExperimentalFoundationApi
43
import androidx.compose.foundation.layout.Arrangement
54
import androidx.compose.foundation.layout.Box
65
import androidx.compose.foundation.layout.Column
@@ -59,7 +58,6 @@ import androidx.compose.ui.text.style.TextOverflow
5958
import androidx.compose.ui.unit.dp
6059
import androidx.lifecycle.compose.collectAsStateWithLifecycle
6160
import io.github.fletchmckee.liquid.liquefiable
62-
import zed.rainxch.githubstore.core.presentation.res.*
6361
import kotlinx.coroutines.delay
6462
import org.jetbrains.compose.resources.stringResource
6563
import org.jetbrains.compose.ui.tooling.preview.Preview
@@ -71,6 +69,11 @@ import zed.rainxch.core.presentation.locals.LocalBottomNavigationLiquid
7169
import zed.rainxch.core.presentation.theme.GithubStoreTheme
7270
import zed.rainxch.domain.model.ProgrammingLanguage
7371
import zed.rainxch.domain.model.SearchPlatform
72+
import zed.rainxch.githubstore.core.presentation.res.Res
73+
import zed.rainxch.githubstore.core.presentation.res.language_label
74+
import zed.rainxch.githubstore.core.presentation.res.results_found
75+
import zed.rainxch.githubstore.core.presentation.res.retry
76+
import zed.rainxch.githubstore.core.presentation.res.search_repositories_hint
7477
import zed.rainxch.search.presentation.components.LanguageFilterBottomSheet
7578
import zed.rainxch.search.presentation.utils.label
7679

@@ -120,7 +123,7 @@ fun SearchRoot(
120123
)
121124
}
122125

123-
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
126+
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
124127
@Composable
125128
fun SearchScreen(
126129
state: SearchState,
@@ -382,7 +385,6 @@ fun SearchScreen(
382385
}
383386
}
384387

385-
@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalFoundationApi::class)
386388
@Composable
387389
private fun SearchTopbar(
388390
onAction: (SearchAction) -> Unit,

feature/search/presentation/src/commonMain/kotlin/zed/rainxch/search/presentation/SearchViewModel.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class SearchViewModel(
226226
currentState.copy(
227227
repositories = allRepos,
228228
hasMorePages = paginatedRepos.hasMore,
229-
totalCount = _state.value.repositories.size,
229+
totalCount = allRepos.size,
230230
errorMessage = if (allRepos.isEmpty() && !paginatedRepos.hasMore) {
231231
getString(Res.string.no_repositories_found)
232232
} else null
@@ -362,7 +362,13 @@ class SearchViewModel(
362362
SearchAction.OnClearClick -> {
363363
_state.update {
364364
it.copy(
365-
query = ""
365+
query = "",
366+
repositories = emptyList(),
367+
isLoading = false,
368+
isLoadingMore = false,
369+
errorMessage = null,
370+
totalCount = null
371+
366372
)
367373
}
368374
}

0 commit comments

Comments
 (0)