mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-30 17:53:31 -04:00 
			
		
		
		
	fix: duplicate network calls on index page (#2085)
* Prevent extra recipe load on index page * Prevent loading recipes with food for all components but search ones * add missing change in search page
This commit is contained in:
		| @@ -183,6 +183,10 @@ export default defineComponent({ | |||||||
|       type: String, |       type: String, | ||||||
|       default: null, |       default: null, | ||||||
|     }, |     }, | ||||||
|  |     skipLoad: { | ||||||
|  |       type: Boolean, | ||||||
|  |       default: false | ||||||
|  |     } | ||||||
|   }, |   }, | ||||||
|   setup(props, context) { |   setup(props, context) { | ||||||
|     const preferences = useUserSortPreferences(); |     const preferences = useUserSortPreferences(); | ||||||
| @@ -233,6 +237,9 @@ export default defineComponent({ | |||||||
|     const { fetchMore } = useLazyRecipes(); |     const { fetchMore } = useLazyRecipes(); | ||||||
|  |  | ||||||
|     onMounted(async () => { |     onMounted(async () => { | ||||||
|  |       if (props.skipLoad) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|       const newRecipes = await fetchMore( |       const newRecipes = await fetchMore( | ||||||
|         page.value, |         page.value, | ||||||
|  |  | ||||||
|   | |||||||
| @@ -65,7 +65,7 @@ export default defineComponent({ | |||||||
|   }, |   }, | ||||||
|  |  | ||||||
|   setup(_, context) { |   setup(_, context) { | ||||||
|     const { refreshRecipes } = useRecipes(true, false); |     const { refreshRecipes } = useRecipes(true, false, true); | ||||||
|  |  | ||||||
|     const state = reactive({ |     const state = reactive({ | ||||||
|       loading: false, |       loading: false, | ||||||
|   | |||||||
| @@ -67,7 +67,7 @@ export const useLazyRecipes = function () { | |||||||
|   }; |   }; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export const useRecipes = (all = false, fetchRecipes = true) => { | export const useRecipes = (all = false, fetchRecipes = true, loadFood = false) => { | ||||||
|   const api = useUserApi(); |   const api = useUserApi(); | ||||||
|  |  | ||||||
|   // recipes is non-reactive!! |   // recipes is non-reactive!! | ||||||
| @@ -88,7 +88,7 @@ export const useRecipes = (all = false, fetchRecipes = true) => { | |||||||
|   })(); |   })(); | ||||||
|  |  | ||||||
|   async function refreshRecipes() { |   async function refreshRecipes() { | ||||||
|     const { data } = await api.recipes.getAll(page, perPage, { loadFood: true, orderBy: "created_at" }); |     const { data } = await api.recipes.getAll(page, perPage, { loadFood, orderBy: "created_at" }); | ||||||
|     if (data) { |     if (data) { | ||||||
|       recipes.value = data.items; |       recipes.value = data.items; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ | |||||||
|       :icon="$globals.icons.primary" |       :icon="$globals.icons.primary" | ||||||
|       :title="$t('general.recent')" |       :title="$t('general.recent')" | ||||||
|       :recipes="recentRecipes" |       :recipes="recentRecipes" | ||||||
|  |       :skip-load="true" | ||||||
|     ></RecipeCardSection> |     ></RecipeCardSection> | ||||||
|   </v-container> |   </v-container> | ||||||
| </template> | </template> | ||||||
|   | |||||||
| @@ -134,7 +134,7 @@ export default defineComponent({ | |||||||
|     RecipeCardSection, |     RecipeCardSection, | ||||||
|   }, |   }, | ||||||
|   setup() { |   setup() { | ||||||
|     const { assignSorted } = useRecipes(true); |     const { assignSorted } = useRecipes(true, true, true); | ||||||
|  |  | ||||||
|     // ================================================================ |     // ================================================================ | ||||||
|     // Advanced Toggle |     // Advanced Toggle | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user