2021-07-31 22:45:28 +00:00
|
|
|
<template>
|
2021-08-03 06:15:11 +00:00
|
|
|
<v-container>
|
|
|
|
<RecipeCardSection
|
|
|
|
:icon="$globals.icons.primary"
|
|
|
|
:title="$t('page.all-recipes')"
|
2021-10-03 22:07:18 +00:00
|
|
|
:recipes="recipes"
|
2021-11-06 05:29:15 +00:00
|
|
|
@delete="removeRecipe"
|
2021-08-03 06:15:11 +00:00
|
|
|
></RecipeCardSection>
|
2021-10-03 22:07:18 +00:00
|
|
|
<v-card v-intersect="infiniteScroll"></v-card>
|
|
|
|
<v-fade-transition>
|
|
|
|
<AppLoader v-if="loading" :loading="loading" />
|
|
|
|
</v-fade-transition>
|
2021-08-03 06:15:11 +00:00
|
|
|
</v-container>
|
|
|
|
</template>
|
2021-07-31 22:45:28 +00:00
|
|
|
|
2021-08-09 04:52:44 +00:00
|
|
|
<script lang="ts">
|
2021-10-03 22:07:18 +00:00
|
|
|
import { defineComponent, onMounted, ref } from "@nuxtjs/composition-api";
|
|
|
|
import { useThrottleFn } from "@vueuse/core";
|
2021-08-03 06:15:11 +00:00
|
|
|
import RecipeCardSection from "~/components/Domain/Recipe/RecipeCardSection.vue";
|
2021-10-03 22:07:18 +00:00
|
|
|
import { useLazyRecipes } from "~/composables/use-recipes";
|
2021-08-03 06:15:11 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: { RecipeCardSection },
|
|
|
|
setup() {
|
2021-10-29 03:28:33 +00:00
|
|
|
const start = ref(0);
|
2021-10-03 22:07:18 +00:00
|
|
|
const limit = ref(30);
|
|
|
|
const increment = ref(30);
|
|
|
|
const ready = ref(false);
|
|
|
|
const loading = ref(false);
|
2021-08-03 06:15:11 +00:00
|
|
|
|
2021-10-03 22:07:18 +00:00
|
|
|
const { recipes, fetchMore } = useLazyRecipes();
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
await fetchMore(start.value, limit.value);
|
|
|
|
ready.value = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
const infiniteScroll = useThrottleFn(() => {
|
|
|
|
if (!ready.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
loading.value = true;
|
|
|
|
start.value = limit.value + 1;
|
|
|
|
limit.value = limit.value + increment.value;
|
|
|
|
fetchMore(start.value, limit.value);
|
|
|
|
loading.value = false;
|
|
|
|
}, 500);
|
|
|
|
|
2021-11-05 02:15:23 +00:00
|
|
|
function removeRecipe(slug: string) {
|
|
|
|
// @ts-ignore
|
|
|
|
for (let i = 0; i < recipes?.value?.length; i++) {
|
|
|
|
// @ts-ignore
|
|
|
|
if (recipes?.value[i].slug === slug) {
|
|
|
|
recipes?.value.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { recipes, infiniteScroll, loading, removeRecipe };
|
2021-08-03 06:15:11 +00:00
|
|
|
},
|
2021-10-07 17:39:47 +00:00
|
|
|
head() {
|
|
|
|
return {
|
|
|
|
title: this.$t("page.all-recipes") as string,
|
|
|
|
};
|
|
|
|
},
|
2021-08-03 06:15:11 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|