in shared/src/commonMain/kotlin/org/jetbrains/kotlinconf/screens/ScheduleViewModel.kt [97:116]
fun toggleFilter(item: FilterItem, selected: Boolean) {
filterItems.update {
val list = it.toMutableList()
if (item.type == FilterItemType.Level || item.type == FilterItemType.Format) {
// Remove previous format or level selection, if there is one
val prevSelectedIndex = list.indexOfFirst { it.type == item.type && it.isSelected }
if (prevSelectedIndex >= 0) {
list[prevSelectedIndex] = list[prevSelectedIndex].copy(isSelected = false)
}
}
val index = list.indexOf(item)
if (index >= 0) {
list[index] = item.copy(isSelected = selected)
}
list
}
}