Fix crash when trying use source sort filter without a pre-selection (#2036)

This commit is contained in:
AntsyLich
2025-04-22 19:02:52 +06:00
committed by GitHub
parent eeab61fc94
commit 1c982c2a01
2 changed files with 17 additions and 14 deletions

View File

@ -128,22 +128,24 @@ private fun FilterItem(filter: Filter<*>, onUpdate: () -> Unit) {
) {
Column {
filter.values.mapIndexed { index, item ->
val sortAscending = filter.state?.ascending
?.takeIf { index == filter.state?.index }
SortItem(
label = item,
sortDescending = filter.state?.ascending?.not()
?.takeIf { index == filter.state?.index },
) {
val ascending = if (index == filter.state?.index) {
!filter.state!!.ascending
} else {
filter.state!!.ascending
}
filter.state = Filter.Sort.Selection(
index = index,
ascending = ascending,
)
onUpdate()
}
sortDescending = if (sortAscending != null) !sortAscending else null,
onClick = {
val ascending = if (index == filter.state?.index) {
!filter.state!!.ascending
} else {
filter.state?.ascending ?: true
}
filter.state = Filter.Sort.Selection(
index = index,
ascending = ascending,
)
onUpdate()
},
)
}
}
}