mealie/frontend/pages/recipes/all.vue
Hayden 788e176b16
Refactor/composables-folder (#787)
* move api clients and rename

* organize recipes composables

* rewrite useRecipeContext

* refactor(frontend): ♻️ abstract common ingredient functionality.

* feat(frontend):  add scale, and back to recipe button + hide ingredients if none

* update regex to mach 11. instead of just 1.

* minor UX improvements

Co-authored-by: Hayden K <hay-kot@pm.me>
2021-11-06 11:28:47 -08:00

69 lines
No EOL
1.8 KiB
Vue

<template>
<v-container>
<RecipeCardSection
:icon="$globals.icons.primary"
:title="$t('page.all-recipes')"
:recipes="recipes"
@delete="removeRecipe"
></RecipeCardSection>
<v-card v-intersect="infiniteScroll"></v-card>
<v-fade-transition>
<AppLoader v-if="loading" :loading="loading" />
</v-fade-transition>
</v-container>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref } from "@nuxtjs/composition-api";
import { useThrottleFn } from "@vueuse/core";
import RecipeCardSection from "~/components/Domain/Recipe/RecipeCardSection.vue";
import { useLazyRecipes } from "~/composables/recipes";
export default defineComponent({
components: { RecipeCardSection },
setup() {
const start = ref(0);
const limit = ref(30);
const increment = ref(30);
const ready = ref(false);
const loading = ref(false);
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);
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 };
},
head() {
return {
title: this.$t("page.all-recipes") as string,
};
},
});
</script>