| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											2021-11-05 21:29:15 -08:00
										 |  |  |       @delete="removeRecipe" | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     ></RecipeCardSection> | 
					
						
							| 
									
										
										
										
											2021-10-03 14:07:18 -08:00
										 |  |  |     <v-card v-intersect="infiniteScroll"></v-card> | 
					
						
							|  |  |  |     <v-fade-transition> | 
					
						
							|  |  |  |       <AppLoader v-if="loading" :loading="loading" /> | 
					
						
							|  |  |  |     </v-fade-transition> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |   </v-container> | 
					
						
							|  |  |  | </template> | 
					
						
							| 
									
										
										
										
											2022-06-15 15:56:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-08 20:52:44 -08:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2021-10-03 14:07:18 -08:00
										 |  |  | import { defineComponent, onMounted, ref } from "@nuxtjs/composition-api"; | 
					
						
							|  |  |  | import { useThrottleFn } from "@vueuse/core"; | 
					
						
							| 
									
										
										
										
											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"; | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							|  |  |  |   components: { RecipeCardSection }, | 
					
						
							|  |  |  |   setup() { | 
					
						
							| 
									
										
										
										
											2022-06-19 13:03:24 -05:00
										 |  |  |     // paging and sorting params
 | 
					
						
							|  |  |  |     const orderBy = "name"; | 
					
						
							|  |  |  |     const orderDescending =  false; | 
					
						
							| 
									
										
										
										
											2021-10-03 14:07:18 -08:00
										 |  |  |     const increment = ref(30); | 
					
						
							| 
									
										
										
										
											2022-06-19 13:03:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const start = ref(0); | 
					
						
							| 
									
										
										
										
											2022-06-15 15:56:56 -05:00
										 |  |  |     const offset = ref(increment.value); | 
					
						
							|  |  |  |     const limit = ref(increment.value); | 
					
						
							| 
									
										
										
										
											2021-10-03 14:07:18 -08:00
										 |  |  |     const ready = ref(false); | 
					
						
							|  |  |  |     const loading = ref(false); | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-03 14:07:18 -08:00
										 |  |  |     const { recipes, fetchMore } = useLazyRecipes(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     onMounted(async () => { | 
					
						
							| 
									
										
										
										
											2022-06-19 13:03:24 -05:00
										 |  |  |       await fetchMore(start.value, limit.value, orderBy, orderDescending); | 
					
						
							| 
									
										
										
										
											2021-10-03 14:07:18 -08:00
										 |  |  |       ready.value = true; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const infiniteScroll = useThrottleFn(() => { | 
					
						
							|  |  |  |       if (!ready.value) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       loading.value = true; | 
					
						
							| 
									
										
										
										
											2022-06-15 15:56:56 -05:00
										 |  |  |       start.value = offset.value + 1; | 
					
						
							|  |  |  |       offset.value = offset.value + increment.value; | 
					
						
							| 
									
										
										
										
											2022-06-19 13:03:24 -05:00
										 |  |  |       fetchMore(start.value, limit.value, orderBy, orderDescending); | 
					
						
							| 
									
										
										
										
											2021-10-03 14:07:18 -08:00
										 |  |  |       loading.value = false; | 
					
						
							|  |  |  |     }, 500); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { recipes, infiniteScroll, loading, removeRecipe }; | 
					
						
							| 
									
										
										
										
											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> |