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-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-03 22:07:18 +00:00
|
|
|
const start = ref(1);
|
|
|
|
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);
|
|
|
|
|
|
|
|
return { recipes, infiniteScroll, loading };
|
2021-08-03 06:15:11 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|