mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 18:23:18 -04:00 
			
		
		
		
	* added sort params to backend call * hardcoded alphabetical sort param * removed trivial type annotation * linters are friends, not food
		
			
				
	
	
		
			72 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			1.9 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() {
 | |
|     // paging and sorting params
 | |
|     const orderBy = "name";
 | |
|     const orderDescending =  false;
 | |
|     const increment = ref(30);
 | |
| 
 | |
|     const start = ref(0);
 | |
|     const offset = ref(increment.value);
 | |
|     const limit = ref(increment.value);
 | |
|     const ready = ref(false);
 | |
|     const loading = ref(false);
 | |
| 
 | |
|     const { recipes, fetchMore } = useLazyRecipes();
 | |
| 
 | |
|     onMounted(async () => {
 | |
|       await fetchMore(start.value, limit.value, orderBy, orderDescending);
 | |
|       ready.value = true;
 | |
|     });
 | |
| 
 | |
|     const infiniteScroll = useThrottleFn(() => {
 | |
|       if (!ready.value) {
 | |
|         return;
 | |
|       }
 | |
|       loading.value = true;
 | |
|       start.value = offset.value + 1;
 | |
|       offset.value = offset.value + increment.value;
 | |
|       fetchMore(start.value, limit.value, orderBy, orderDescending);
 | |
|       loading.value = false;
 | |
|     }, 500);
 | |
| 
 | |
|     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;
 | |
|         }
 | |
|       }
 | |
|     }
 | |
| 
 | |
|     return { recipes, infiniteScroll, loading, removeRecipe };
 | |
|   },
 | |
|   head() {
 | |
|     return {
 | |
|       title: this.$t("page.all-recipes") as string,
 | |
|     };
 | |
|   },
 | |
| });
 | |
| </script>
 |