feat: add re-roll button to meal planner entries (#7348)

Co-authored-by: Michael Genson <genson.michael@gmail.com>
This commit is contained in:
smashngrabb
2026-07-31 04:02:44 +08:00
committed by GitHub
parent c53b0118f6
commit 1a595d4d0f
2 changed files with 32 additions and 2 deletions
+2 -1
View File
@@ -410,7 +410,8 @@
"applies-on-days": "Applies on {0}s",
"meal-plan-settings": "Meal Plan Settings",
"add-all-to-list": "Add All to List",
"add-day-to-list": "Add Day to List"
"add-day-to-list": "Add Day to List",
"randomize-recipe": "Randomize Recipe"
},
"migration": {
"migration-data-removed": "Migration data removed",
@@ -155,7 +155,18 @@
</v-list-item>
</v-list>
</v-menu>
<v-btn class="ml-auto" size="small" variant="text" icon @click="actions.deleteOne(mealplan.id)">
<v-btn
v-if="mealplan.recipe && mealplan.entryType"
class="ml-auto"
size="small"
variant="text"
icon
:title="$t('meal-plan.randomize-recipe')"
@click="randomizeMeal(mealplan)"
>
<v-icon>{{ $globals.icons.diceMultiple }}</v-icon>
</v-btn>
<v-btn :class="{ 'ml-auto': !mealplan.recipe || !mealplan.entryType }" size="small" variant="text" icon @click="actions.deleteOne(mealplan.id)">
<v-icon>{{ $globals.icons.delete }}</v-icon>
</v-btn>
</div>
@@ -391,6 +402,24 @@ async function randomMeal(date: Date, type: PlanEntryType) {
}
}
async function randomizeMeal(mealplan: UpdatePlanEntry) {
if (!mealplan.entryType) {
return;
}
// Delete the current entry, then create a new random one with the same date and type
const { data: deleted } = await api.mealplans.deleteOne(mealplan.id);
if (deleted) {
await api.mealplans.setRandom({
date: mealplan.date,
entryType: mealplan.entryType,
});
// Refresh either way: if setRandom failed we still need to reflect the deletion
props.actions.refreshAll();
}
}
// =====================================================
// Search