mirror of https://github.com/readrops/Readrops.git
Improve state hoisting in FilterBottomSheet
This commit is contained in:
parent
8011759076
commit
32e0c17e08
|
@ -24,7 +24,8 @@ import com.readrops.db.queries.QueryFilters
|
|||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun FilterBottomSheet(
|
||||
viewModel: TimelineScreenModel,
|
||||
onSetShowReadItemsState: () -> Unit,
|
||||
onSetSortTypeState: () -> Unit,
|
||||
filters: QueryFilters,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
|
@ -44,11 +45,11 @@ fun FilterBottomSheet(
|
|||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { viewModel.setShowReadItemsState(!filters.showReadItems) }
|
||||
.clickable(onClick = onSetShowReadItemsState)
|
||||
) {
|
||||
Checkbox(
|
||||
checked = filters.showReadItems,
|
||||
onCheckedChange = { viewModel.setShowReadItemsState(!filters.showReadItems) }
|
||||
onCheckedChange = { onSetShowReadItemsState() }
|
||||
)
|
||||
|
||||
ShortSpacer()
|
||||
|
@ -60,24 +61,15 @@ fun FilterBottomSheet(
|
|||
|
||||
ShortSpacer()
|
||||
|
||||
fun setSortTypeState() {
|
||||
viewModel.setSortTypeState(
|
||||
if (filters.sortType == ListSortType.NEWEST_TO_OLDEST)
|
||||
ListSortType.OLDEST_TO_NEWEST
|
||||
else
|
||||
ListSortType.NEWEST_TO_OLDEST
|
||||
)
|
||||
}
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { setSortTypeState() }
|
||||
.clickable(onClick = onSetSortTypeState)
|
||||
) {
|
||||
Checkbox(
|
||||
checked = filters.sortType == ListSortType.OLDEST_TO_NEWEST,
|
||||
onCheckedChange = { setSortTypeState() }
|
||||
onCheckedChange = { onSetSortTypeState() }
|
||||
)
|
||||
|
||||
ShortSpacer()
|
||||
|
|
|
@ -50,6 +50,7 @@ import com.readrops.app.compose.util.components.CenteredProgressIndicator
|
|||
import com.readrops.app.compose.util.components.Placeholder
|
||||
import com.readrops.app.compose.util.components.TwoChoicesDialog
|
||||
import com.readrops.app.compose.util.theme.spacing
|
||||
import com.readrops.db.filters.ListSortType
|
||||
import com.readrops.db.filters.MainFilter
|
||||
import com.readrops.db.filters.SubFilter
|
||||
|
||||
|
@ -137,8 +138,18 @@ object TimelineTab : Tab {
|
|||
|
||||
DialogState.FilterSheet -> {
|
||||
FilterBottomSheet(
|
||||
viewModel = viewModel,
|
||||
filters = state.filters,
|
||||
onSetShowReadItemsState = {
|
||||
viewModel.setShowReadItemsState(!state.filters.showReadItems)
|
||||
},
|
||||
onSetSortTypeState = {
|
||||
viewModel.setSortTypeState(
|
||||
if (state.filters.sortType == ListSortType.NEWEST_TO_OLDEST)
|
||||
ListSortType.OLDEST_TO_NEWEST
|
||||
else
|
||||
ListSortType.NEWEST_TO_OLDEST
|
||||
)
|
||||
},
|
||||
onDismiss = {
|
||||
viewModel.closeDialog()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue