Skip to content

Commit

Permalink
Handle meal removal
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuwu committed Apr 29, 2024
1 parent 7194348 commit 7ae7e36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.hieuwu.groceriesstore.domain.models.MealModel
import com.hieuwu.groceriesstore.domain.usecases.AddMealToPlanUseCase
import com.hieuwu.groceriesstore.domain.usecases.RemoveMealFromPlanUseCase
import com.hieuwu.groceriesstore.domain.usecases.RetrieveMealByTypeUseCase
import com.hieuwu.groceriesstore.presentation.mealplanning.overview.state.Meal
import com.hieuwu.groceriesstore.presentation.mealplanning.overview.state.MealType
Expand All @@ -19,6 +20,7 @@ import javax.inject.Inject
class OverviewViewModel @Inject constructor(
private val addMealToPlanUseCase: AddMealToPlanUseCase,
private val retrieveMealByTypeUseCase: RetrieveMealByTypeUseCase,
private val removeMealFromPlanUseCase: RemoveMealFromPlanUseCase
) : ViewModel() {

private val _days = MutableStateFlow(
Expand Down Expand Up @@ -122,6 +124,16 @@ class OverviewViewModel @Inject constructor(
retrieveMeal(WeekDayValue.valueOf(_days.value[selectedDayIndex].name))
}

fun onRemoveMeal(id: String) {
viewModelScope.launch {
removeMealFromPlanUseCase.execute(
RemoveMealFromPlanUseCase.Input(
id = id
)
)
}
}

fun onAddMeal(mealType: MealType, name: String, ingredients: List<String>) {
when (mealType) {
MealType.BREAKFAST -> onAddBreakfast(name, ingredients)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.material.Text
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand All @@ -26,14 +25,13 @@ import androidx.compose.ui.unit.dp
import com.hieuwu.groceriesstore.presentation.core.widgets.WebImage
import com.hieuwu.groceriesstore.presentation.mealplanning.overview.state.Meal

@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun MealItem(
modifier: Modifier = Modifier,
meal: Meal
) {
Card(
onClick = { /*TODO*/ },
modifier = modifier
.height(164.dp)
.fillMaxWidth(),
Expand Down

0 comments on commit 7ae7e36

Please sign in to comment.