mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 02:03:35 -04:00 
			
		
		
		
	fix: Recipe Card Section Infinite Loop (#2584)
* refactored recipe card section fetch * minor optimization * lint
This commit is contained in:
		| @@ -244,32 +244,37 @@ export default defineComponent({ | |||||||
|  |  | ||||||
|     onMounted(async () => { |     onMounted(async () => { | ||||||
|       if (props.query) { |       if (props.query) { | ||||||
|         const newRecipes = await fetchRecipes(2); |         await initRecipes(); | ||||||
|  |  | ||||||
|         // since we doubled the first call, we also need to advance the page |  | ||||||
|         page.value = page.value + 1; |  | ||||||
|  |  | ||||||
|         context.emit(REPLACE_RECIPES_EVENT, newRecipes); |  | ||||||
|         ready.value = true; |         ready.value = true; | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     let lastQuery: string | undefined; | ||||||
|     watch( |     watch( | ||||||
|       () => props.query, |       () => props.query, | ||||||
|       async (newValue: RecipeSearchQuery | undefined) => { |       async (newValue: RecipeSearchQuery | undefined) => { | ||||||
|         if (newValue) { |         const newValueString = JSON.stringify(newValue) | ||||||
|           page.value = 1; |         if (newValue && (!ready.value || lastQuery !== newValueString)) { | ||||||
|           const newRecipes = await fetchRecipes(2); |           lastQuery = newValueString; | ||||||
|  |           await initRecipes(); | ||||||
|           // since we doubled the first call, we also need to advance the page |  | ||||||
|           page.value = page.value + 1; |  | ||||||
|  |  | ||||||
|           context.emit(REPLACE_RECIPES_EVENT, newRecipes); |  | ||||||
|           ready.value = true; |           ready.value = true; | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|  |     async function initRecipes() { | ||||||
|  |       page.value = 1; | ||||||
|  |       const newRecipes = await fetchRecipes(2); | ||||||
|  |       if (!newRecipes.length) { | ||||||
|  |         hasMore.value = false; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       // since we doubled the first call, we also need to advance the page | ||||||
|  |       page.value = page.value + 1; | ||||||
|  |  | ||||||
|  |       context.emit(REPLACE_RECIPES_EVENT, newRecipes); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     const infiniteScroll = useThrottleFn(() => { |     const infiniteScroll = useThrottleFn(() => { | ||||||
|       useAsync(async () => { |       useAsync(async () => { | ||||||
|         if (!ready.value || !hasMore.value || loading.value) { |         if (!ready.value || !hasMore.value || loading.value) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user