BrowseSourceScreen: fix navigate up and filter sheet (#8761)

This commit is contained in:
stevenyomi 2022-12-18 02:21:12 +08:00 committed by GitHub
parent 9d2d78ae5b
commit 817e144ff6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View File

@ -84,6 +84,13 @@ data class BrowseSourceScreen(
val snackbarHostState = remember { SnackbarHostState() } val snackbarHostState = remember { SnackbarHostState() }
val navigateUp: () -> Unit = {
when {
!state.isUserQuery && state.toolbarQuery != null -> screenModel.setToolbarQuery(null)
else -> navigator.pop()
}
}
val onHelpClick = { uriHandler.openUri(LocalSource.HELP_URL) } val onHelpClick = { uriHandler.openUri(LocalSource.HELP_URL) }
val onWebViewClick = f@{ val onWebViewClick = f@{
@ -105,7 +112,7 @@ data class BrowseSourceScreen(
source = screenModel.source, source = screenModel.source,
displayMode = screenModel.displayMode, displayMode = screenModel.displayMode,
onDisplayModeChange = { screenModel.displayMode = it }, onDisplayModeChange = { screenModel.displayMode = it },
navigateUp = navigator::pop, navigateUp = navigateUp,
onWebViewClick = onWebViewClick, onWebViewClick = onWebViewClick,
onHelpClick = onHelpClick, onHelpClick = onHelpClick,
onSearch = { screenModel.search(it) }, onSearch = { screenModel.search(it) },

View File

@ -359,21 +359,20 @@ class BrowseSourceScreenModel(
} }
fun initFilterSheet(context: Context) { fun initFilterSheet(context: Context) {
val state = state.value if (state.value.filters.isEmpty()) {
if (state.filters.isEmpty()) {
return return
} }
filterSheet = SourceFilterSheet( filterSheet = SourceFilterSheet(
context = context, context = context,
onFilterClicked = { search(filters = state.filters) }, onFilterClicked = { search(filters = state.value.filters) },
onResetClicked = { onResetClicked = {
reset() reset()
filterSheet?.setFilters(state.filterItems) filterSheet?.setFilters(state.value.filterItems)
}, },
) )
filterSheet?.setFilters(state.filterItems) filterSheet?.setFilters(state.value.filterItems)
} }
sealed class Filter(open val query: String?, open val filters: FilterList) { sealed class Filter(open val query: String?, open val filters: FilterList) {
@ -409,12 +408,8 @@ class BrowseSourceScreenModel(
val toolbarQuery: String? = null, val toolbarQuery: String? = null,
val dialog: Dialog? = null, val dialog: Dialog? = null,
) { ) {
val filterItems = filters.toItems() val filterItems get() = filters.toItems()
val isUserQuery = currentFilter is Filter.UserInput && !currentFilter.query.isNullOrEmpty() val isUserQuery get() = currentFilter is Filter.UserInput && !currentFilter.query.isNullOrEmpty()
val searchQuery = when (currentFilter) {
is Filter.UserInput -> currentFilter.query
Filter.Latest, Filter.Popular -> null
}
} }
} }