updated RecipeSwitcher with new MealPlan API format

This commit is contained in:
smilerz 2023-12-19 16:50:32 -06:00
parent 99cd9bfb5b
commit 48dacf46c3
No known key found for this signature in database
GPG Key ID: 39444C7606D47126

View File

@ -3,8 +3,7 @@
<div id="switcher" class="align-center"> <div id="switcher" class="align-center">
<i class="btn btn-primary fas fa-receipt fa-xl fa-fw shadow-none btn-circle" v-b-toggle.related-recipes /> <i class="btn btn-primary fas fa-receipt fa-xl fa-fw shadow-none btn-circle" v-b-toggle.related-recipes />
</div> </div>
<b-sidebar id="related-recipes" backdrop right bottom no-header shadow="sm" style="z-index: 10000" <b-sidebar id="related-recipes" backdrop right bottom no-header shadow="sm" style="z-index: 10000" @shown="updatePinnedRecipes()">
@shown="updatePinnedRecipes()">
<template #default="{ hide }"> <template #default="{ hide }">
<div class="d-flex flex-column justify-content-end h-100 p-3 align-items-end"> <div class="d-flex flex-column justify-content-end h-100 p-3 align-items-end">
<h5>{{ $t("Planned") }} <i class="fas fa-calendar fa-fw"></i></h5> <h5>{{ $t("Planned") }} <i class="fas fa-calendar fa-fw"></i></h5>
@ -36,8 +35,7 @@
<div v-for="r in pinned_recipes" :key="`pin${r.id}`"> <div v-for="r in pinned_recipes" :key="`pin${r.id}`">
<b-row class="pb-1 pt-1"> <b-row class="pb-1 pt-1">
<b-col cols="2"> <b-col cols="2">
<a href="javascript:void(0)" @click="unPinRecipe(r)" class="text-muted"><i <a href="javascript:void(0)" @click="unPinRecipe(r)" class="text-muted"><i class="fas fa-times"></i></a>
class="fas fa-times"></i></a>
</b-col> </b-col>
<b-col cols="10"> <b-col cols="10">
<a <a
@ -160,12 +158,14 @@ export default {
// get related recipes and save them for later // get related recipes and save them for later
if (this.$parent.recipe) { if (this.$parent.recipe) {
this.related_recipes = [this.$parent.recipe] this.related_recipes = [this.$parent.recipe]
return apiClient.relatedRecipe(this.$parent.recipe.id, { return apiClient
.relatedRecipe(this.$parent.recipe.id, {
query: { query: {
levels: 2, levels: 2,
format: "json" format: "json",
} },
}).then((result) => { })
.then((result) => {
this.related_recipes = this.related_recipes.concat(result.data) this.related_recipes = this.related_recipes.concat(result.data)
}) })
} }
@ -179,7 +179,7 @@ export default {
// TODO move to utility function moment is in maintenance mode https://momentjs.com/docs/ // TODO move to utility function moment is in maintenance mode https://momentjs.com/docs/
var tzoffset = new Date().getTimezoneOffset() * 60000 //offset in milliseconds var tzoffset = new Date().getTimezoneOffset() * 60000 //offset in milliseconds
let today = new Date(Date.now() - tzoffset).toISOString().split("T")[0] let today = new Date(Date.now() - tzoffset).toISOString().split("T")[0]
return apiClient.listMealPlans({query: {from_date: today, to_date: today}}).then((result) => { return apiClient.listMealPlans(today, today).then((result) => {
let promises = [] let promises = []
result.data.forEach((mealplan) => { result.data.forEach((mealplan) => {
this.planned_recipes.push({ ...mealplan?.recipe, servings: mealplan?.servings }) this.planned_recipes.push({ ...mealplan?.recipe, servings: mealplan?.servings })
@ -220,7 +220,6 @@ export default {
z-index: 9000; z-index: 9000;
} }
@media (max-width: 991.98px) { @media (max-width: 991.98px) {
#switcher .btn-circle { #switcher .btn-circle {
position: fixed; position: fixed;