1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-19 13:19:41 +02:00
mealie/frontend/src/pages/HomePage.vue
Hayden be378cb20c
feature/recipe-patch-improvements (#382)
* automated docs update

* recipe rating component

* recipe partial updates - closes #25

* use Vue.delete to update store

* format

* arrow functions

* fix tests

* format

* initial context menu

* localize

* add confirmation dialog

* context menu

* fix bare exception

* update line length

* format all file with prettier

* update changelog

* download as json

* update python dependencies

* update javascript dependencies

Co-authored-by: hay-kot <hay-kot@pm.me>
2021-05-01 20:46:02 -08:00

73 lines
1.9 KiB
Vue

<template>
<v-container>
<CardSection
v-if="siteSettings.showRecent"
:title="$t('page.recent')"
:recipes="recentRecipes"
:hard-limit="siteSettings.cardsPerSection"
/>
<CardSection
:sortable="true"
v-for="(section, index) in recipeByCategory"
:key="section.name + section.position"
:title="section.name"
:recipes="section.recipes"
:hard-limit="siteSettings.cardsPerSection"
@sort="sortAZ(index)"
@sort-recent="sortRecent(index)"
/>
</v-container>
</template>
<script>
import { api } from "@/api";
import CardSection from "../components/UI/CardSection";
export default {
components: {
CardSection,
},
data() {
return {
recipeByCategory: [],
};
},
computed: {
siteSettings() {
return this.$store.getters.getSiteSettings;
},
recentRecipes() {
console.log("Recent Recipes");
return this.$store.getters.getRecentRecipes;
},
},
async mounted() {
await this.buildPage();
this.recipeByCategory.sort((a, b) => a.position - b.position);
},
methods: {
async buildPage() {
await this.$store.dispatch("requestSiteSettings");
this.siteSettings.categories.forEach(async element => {
let recipes = await this.getRecipeByCategory(element.slug);
if (recipes.recipes.length < 0) recipes.recipes = [];
this.recipeByCategory.push(recipes);
});
},
async getRecipeByCategory(category) {
return await api.categories.getRecipesInCategory(category);
},
getRecentRecipes() {
this.$store.dispatch("requestRecentRecipes");
},
sortAZ(index) {
this.recipeByCategory[index].recipes.sort((a, b) => (a.name > b.name ? 1 : -1));
},
sortRecent(index) {
this.recipeByCategory[index].recipes.sort((a, b) => (a.dateAdded > b.dateAdded ? -1 : 1));
},
},
};
</script>
<style></style>