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)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun FilterBottomSheet(
|
fun FilterBottomSheet(
|
||||||
viewModel: TimelineScreenModel,
|
onSetShowReadItemsState: () -> Unit,
|
||||||
|
onSetSortTypeState: () -> Unit,
|
||||||
filters: QueryFilters,
|
filters: QueryFilters,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
) {
|
) {
|
||||||
|
@ -44,11 +45,11 @@ fun FilterBottomSheet(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable { viewModel.setShowReadItemsState(!filters.showReadItems) }
|
.clickable(onClick = onSetShowReadItemsState)
|
||||||
) {
|
) {
|
||||||
Checkbox(
|
Checkbox(
|
||||||
checked = filters.showReadItems,
|
checked = filters.showReadItems,
|
||||||
onCheckedChange = { viewModel.setShowReadItemsState(!filters.showReadItems) }
|
onCheckedChange = { onSetShowReadItemsState() }
|
||||||
)
|
)
|
||||||
|
|
||||||
ShortSpacer()
|
ShortSpacer()
|
||||||
|
@ -60,24 +61,15 @@ fun FilterBottomSheet(
|
||||||
|
|
||||||
ShortSpacer()
|
ShortSpacer()
|
||||||
|
|
||||||
fun setSortTypeState() {
|
|
||||||
viewModel.setSortTypeState(
|
|
||||||
if (filters.sortType == ListSortType.NEWEST_TO_OLDEST)
|
|
||||||
ListSortType.OLDEST_TO_NEWEST
|
|
||||||
else
|
|
||||||
ListSortType.NEWEST_TO_OLDEST
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable { setSortTypeState() }
|
.clickable(onClick = onSetSortTypeState)
|
||||||
) {
|
) {
|
||||||
Checkbox(
|
Checkbox(
|
||||||
checked = filters.sortType == ListSortType.OLDEST_TO_NEWEST,
|
checked = filters.sortType == ListSortType.OLDEST_TO_NEWEST,
|
||||||
onCheckedChange = { setSortTypeState() }
|
onCheckedChange = { onSetSortTypeState() }
|
||||||
)
|
)
|
||||||
|
|
||||||
ShortSpacer()
|
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.Placeholder
|
||||||
import com.readrops.app.compose.util.components.TwoChoicesDialog
|
import com.readrops.app.compose.util.components.TwoChoicesDialog
|
||||||
import com.readrops.app.compose.util.theme.spacing
|
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.MainFilter
|
||||||
import com.readrops.db.filters.SubFilter
|
import com.readrops.db.filters.SubFilter
|
||||||
|
|
||||||
|
@ -137,8 +138,18 @@ object TimelineTab : Tab {
|
||||||
|
|
||||||
DialogState.FilterSheet -> {
|
DialogState.FilterSheet -> {
|
||||||
FilterBottomSheet(
|
FilterBottomSheet(
|
||||||
viewModel = viewModel,
|
|
||||||
filters = state.filters,
|
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 = {
|
onDismiss = {
|
||||||
viewModel.closeDialog()
|
viewModel.closeDialog()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue