Skip to content

Instantly share code, notes, and snippets.

@MohamedGouaouri
Created April 14, 2023 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MohamedGouaouri/b468c315d1025b99c37ccf3dc049adc5 to your computer and use it in GitHub Desktop.
Save MohamedGouaouri/b468c315d1025b99c37ccf3dc049adc5 to your computer and use it in GitHub Desktop.
class RestaurantsViewModel: ViewModel() {
private val _restaurantsState by mutableStateOf(
restaurants
)
val restaurantsState = _restaurantsState
fun toggleIsFavourite(
rid: Int,
) {
var indexToSearch = -1
_restaurantsState.filterIndexed { index, restaurant ->
val found = restaurant.id == rid
if (found) {
indexToSearch = index
}
restaurant.id == rid
}
if (indexToSearch > -1){
_restaurantsState[indexToSearch].isFavourite = !_restaurantsState[indexToSearch].isFavourite
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment