Created
April 14, 2023 16:50
-
-
Save MohamedGouaouri/b468c315d1025b99c37ccf3dc049adc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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