2021-07-31 14:45:28 -08:00
|
|
|
<template>
|
2021-08-02 22:15:11 -08:00
|
|
|
<v-container>
|
|
|
|
<RecipeCardSection
|
|
|
|
:icon="$globals.icons.primary"
|
|
|
|
:title="$t('page.all-recipes')"
|
2021-10-03 14:07:18 -08:00
|
|
|
:recipes="recipes"
|
2022-07-26 21:08:56 -05:00
|
|
|
:use-pagination="true"
|
|
|
|
@sortRecipes="assignSorted"
|
|
|
|
@replaceRecipes="replaceRecipes"
|
|
|
|
@appendRecipes="appendRecipes"
|
2021-11-05 21:29:15 -08:00
|
|
|
@delete="removeRecipe"
|
2021-08-02 22:15:11 -08:00
|
|
|
></RecipeCardSection>
|
|
|
|
</v-container>
|
|
|
|
</template>
|
2022-06-15 15:56:56 -05:00
|
|
|
|
2021-08-08 20:52:44 -08:00
|
|
|
<script lang="ts">
|
2022-07-26 21:08:56 -05:00
|
|
|
import { defineComponent } from "@nuxtjs/composition-api";
|
2021-08-02 22:15:11 -08:00
|
|
|
import RecipeCardSection from "~/components/Domain/Recipe/RecipeCardSection.vue";
|
2021-11-06 11:28:47 -08:00
|
|
|
import { useLazyRecipes } from "~/composables/recipes";
|
2022-07-26 21:08:56 -05:00
|
|
|
import { Recipe } from "~/types/api-types/recipe";
|
2021-08-02 22:15:11 -08:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: { RecipeCardSection },
|
|
|
|
setup() {
|
2021-10-03 14:07:18 -08:00
|
|
|
const { recipes, fetchMore } = useLazyRecipes();
|
|
|
|
|
2022-07-26 21:08:56 -05:00
|
|
|
function appendRecipes(val: Array<Recipe>) {
|
|
|
|
val.forEach((recipe) => {
|
|
|
|
recipes.value.push(recipe);
|
|
|
|
});
|
|
|
|
}
|
2021-10-03 14:07:18 -08:00
|
|
|
|
2022-07-26 21:08:56 -05:00
|
|
|
function assignSorted(val: Array<Recipe>) {
|
|
|
|
recipes.value = val;
|
|
|
|
}
|
2021-10-03 14:07:18 -08:00
|
|
|
|
2021-11-04 18:15:23 -08:00
|
|
|
function removeRecipe(slug: string) {
|
|
|
|
for (let i = 0; i < recipes?.value?.length; i++) {
|
|
|
|
if (recipes?.value[i].slug === slug) {
|
|
|
|
recipes?.value.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 21:08:56 -05:00
|
|
|
function replaceRecipes(val: Array<Recipe>) {
|
|
|
|
recipes.value = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { appendRecipes, assignSorted, recipes, removeRecipe, replaceRecipes };
|
2021-08-02 22:15:11 -08:00
|
|
|
},
|
2021-10-07 09:39:47 -08:00
|
|
|
head() {
|
|
|
|
return {
|
|
|
|
title: this.$t("page.all-recipes") as string,
|
|
|
|
};
|
|
|
|
},
|
2021-08-02 22:15:11 -08:00
|
|
|
});
|
|
|
|
</script>
|