2025-08-08 23:21:33 +03:00
|
|
|
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() {
|
2025-08-09 18:09:09 +03:00
|
|
|
private val _activeRecipe = MutableStateFlow<RecipeWithTags?>( null )
|
2025-08-08 23:21:33 +03:00
|
|
|
val activeRecipe = _activeRecipe.asStateFlow()
|
|
|
|
|
|
2025-08-09 18:09:09 +03:00
|
|
|
private val _recipes = MutableStateFlow<List<RecipeWithTags>>( arrayListOf() )
|
2025-08-08 23:21:33 +03:00
|
|
|
val recipes = _recipes.asStateFlow()
|
|
|
|
|
|
2025-08-09 13:21:06 +03:00
|
|
|
private val _search = MutableStateFlow<String?>(null)
|
|
|
|
|
val search = _search.asStateFlow()
|
|
|
|
|
|
2025-08-09 18:09:09 +03:00
|
|
|
fun setRecipes(recipes: List<RecipeWithTags>) {
|
|
|
|
|
_recipes.update { recipes }
|
2025-08-09 13:21:06 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-09 18:09:09 +03:00
|
|
|
fun setSearch(search: String) {
|
|
|
|
|
_search.update { search }
|
2025-08-08 23:21:33 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-09 18:09:09 +03:00
|
|
|
fun setActive(recipe: RecipeWithTags) {
|
2025-08-08 23:21:33 +03:00
|
|
|
_activeRecipe.update { recipe }
|
|
|
|
|
}
|
|
|
|
|
}
|