recipe-kt/app/src/main/java/xyz/pixelatedw/recipe/data/RecipesView.kt

30 lines
795 B
Kotlin

package xyz.pixelatedw.recipe.data
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
class RecipesView : ViewModel() {
private val _activeRecipe = MutableStateFlow<RecipeWithTags?>( null )
val activeRecipe = _activeRecipe.asStateFlow()
private val _recipes = MutableStateFlow<List<RecipeWithTags>>( arrayListOf() )
val recipes = _recipes.asStateFlow()
private val _search = MutableStateFlow<String?>(null)
val search = _search.asStateFlow()
fun setRecipes(recipes: List<RecipeWithTags>) {
_recipes.update { recipes }
}
fun setSearch(search: String) {
_search.update { search }
}
fun setActive(recipe: RecipeWithTags) {
_activeRecipe.update { recipe }
}
}