Skip to content

Commit

Permalink
Swipe to delete meal
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuwu committed Apr 29, 2024
1 parent 7ae7e36 commit c0c80e0
Showing 1 changed file with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.hieuwu.groceriesstore.presentation.mealplanning.addmeal.AddMealBottom
import com.hieuwu.groceriesstore.presentation.mealplanning.overview.composable.EmptyListIndicatorText
import com.hieuwu.groceriesstore.presentation.mealplanning.overview.composable.LineTextButton
import com.hieuwu.groceriesstore.presentation.mealplanning.overview.composable.MealItem
import com.hieuwu.groceriesstore.presentation.mealplanning.overview.composable.SwipeToDeleteContainer
import com.hieuwu.groceriesstore.presentation.mealplanning.overview.composable.WeekDayItem
import com.hieuwu.groceriesstore.presentation.mealplanning.overview.state.MealType
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -138,8 +139,15 @@ fun OverViewScreen(
)
}
if (breakfastList.isNotEmpty()) {
items(breakfastList) { meal ->
MealItem(meal = meal)
items(breakfastList, key = { it.id }) { meal ->
SwipeToDeleteContainer(
item = meal,
onDelete = {
viewModel.onRemoveMeal(meal.id)
}
) { meal ->
MealItem(meal = meal, modifier = modifier.padding(16.dp))
}
}
} else {
item {
Expand All @@ -159,19 +167,22 @@ fun OverViewScreen(
}

if (lunchMeals.isNotEmpty()) {
items(lunchMeals) { meal ->
MealItem(meal = meal, modifier = modifier)
items(lunchMeals, key = { it.id }) { meal ->
SwipeToDeleteContainer(
item = meal,
onDelete = {
viewModel.onRemoveMeal(meal.id)
}
) { meal ->
MealItem(meal = meal, modifier = modifier.padding(16.dp))
}
}
} else {
item {
EmptyListIndicatorText()
}
}

items(lunchMeals) { meal ->
MealItem(meal = meal, modifier = modifier)
}

item {
LineTextButton(
modifier = modifier,
Expand All @@ -184,8 +195,15 @@ fun OverViewScreen(
}

if (dinnerMeals.isNotEmpty()) {
items(dinnerMeals) { meal ->
MealItem(meal = meal, modifier = modifier)
items(dinnerMeals, key = { it.id }) { meal ->
SwipeToDeleteContainer(
item = meal,
onDelete = {
viewModel.onRemoveMeal(meal.id)
}
) { meal ->
MealItem(meal = meal, modifier = modifier.padding(16.dp))
}
}
} else {
item {
Expand Down

0 comments on commit c0c80e0

Please sign in to comment.