meal plan store and start page widget

This commit is contained in:
vabene1111
2024-03-17 11:45:39 +01:00
parent 7b9d140e74
commit b7c2b5c294
2 changed files with 188 additions and 1 deletions

View File

@@ -1,6 +1,51 @@
<template>
<v-container>
<v-row justify="space-between">
<v-col>
<h2><i class="fas fa-calendar-week fa-fw"></i> Meal Plan</h2>
</v-col>
</v-row>
<v-row>
<v-col v-for="day in meal_plan_grid">
<v-list density="compact">
<v-list-item>
{{ day.date_label }}
</v-list-item>
<v-divider></v-divider>
<v-list-item v-for="p in day.plan_entries">
<template #prepend>
<v-avatar :image="p.recipe.image" v-if="p.recipe?.image"></v-avatar>
<v-avatar image="../../assets/recipe_no_image.svg" v-else></v-avatar>
</template>
<v-list-item-title>
<span v-if="p.recipe">{{ p.recipe.name }}</span>
<span v-else>{{ p.title }}</span>
</v-list-item-title>
<v-list-item-subtitle>
{{ p.mealType.name }}
</v-list-item-subtitle>
</v-list-item>
</v-list>
</v-col>
</v-row>
<v-row>
<v-col>
<v-window show-arrows>
<v-window-item>
<v-row>
</v-row>
</v-window-item>
</v-window>
</v-col>
</v-row>
<!--TODO ideas for "start page": new recipes, meal plan, "last year/month/cooked long ago", high rated, random keyword -->
<horizontal-recipe-scroller title="New Recipes" :skeletons="4" :recipes="new_recipes" icon="fas fa-calendar-alt"></horizontal-recipe-scroller>
<horizontal-recipe-scroller title="Top Rated" :skeletons="2" :recipes="high_rated_recipes" icon="fas fa-star"></horizontal-recipe-scroller>
@@ -18,12 +63,34 @@ import RecipeCardComponent from "@/components/display/RecipeCard.vue";
import GlobalSearchDialog from "@/components/inputs/GlobalSearchDialog.vue";
import RecipeCard from "@/components/display/RecipeCard.vue";
import HorizontalRecipeScroller from "@/components/display/HorizontalRecipeScroller.vue";
import {DateTime} from "luxon";
import {useMealPlanStore} from "@/stores/MealPlanStore";
export default defineComponent({
name: "RecipeSearchPage",
components: {HorizontalRecipeScroller, RecipeCard, GlobalSearchDialog, RecipeCardComponent, KeywordsComponent},
computed: {},
computed: {
meal_plan_grid: function () {
let grid = []
if (useMealPlanStore().plan_list.length > 0) {
console.log('found plans')
for (const x of Array(4).keys()) {
let grid_day_date = DateTime.now().plus({days: x})
console.log('going trough days ', x, grid_day_date)
grid.push({
date: grid_day_date,
create_default_date: grid_day_date.toISODate(), // improve meal plan edit modal to do formatting itself and accept dates
date_label: grid_day_date.toLocaleString(DateTime.DATE_MED),
plan_entries: useMealPlanStore().plan_list.filter(m => (DateTime.fromJSDate(m.fromDate) <= grid_day_date && DateTime.fromJSDate((m.toDate != undefined) ? m.toDate : m.fromDate) >= grid_day_date)),
})
}
}
return grid
},
},
data() {
return {
recipes: [] as Recipe[],
@@ -37,6 +104,9 @@ export default defineComponent({
},
mounted() {
const api = new ApiApi()
useMealPlanStore().refreshFromAPI(DateTime.now().toJSDate(), DateTime.now().plus({days: 7}).toJSDate())
api.apiRecipeList({_new: 'true', pageSize: 16}).then(r => {
if (r.results != undefined) { // TODO openapi generator makes arrays nullable for some reason
this.new_recipes = r.results