mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-03 11:08:18 -05:00 
			
		
		
		
	* add document title to server spa meta * removed conflicting useMeta * replaced head with useMeta * formalized metadata injection * small injection refactor * added tests * added missing global tag * fixed setting tab title for logged-in users * simplified metadata update * remove duplicate tag and fix for foreign users * add metadata for shared recipes * added default recipe image * fixed shared URL --------- Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
		
			
				
	
	
		
			61 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
<template>
 | 
						|
  <div>
 | 
						|
    <RecipePage v-if="recipe" :recipe="recipe" />
 | 
						|
  </div>
 | 
						|
</template>
 | 
						|
 | 
						|
<script lang="ts">
 | 
						|
import { computed, defineComponent, ref, useAsync, useContext, useMeta, useRoute, useRouter } from "@nuxtjs/composition-api";
 | 
						|
import { whenever } from "@vueuse/core";
 | 
						|
import { useLoggedInState } from "~/composables/use-logged-in-state";
 | 
						|
import { useAsyncKey } from "~/composables/use-utils";
 | 
						|
import RecipePage from "~/components/Domain/Recipe/RecipePage/RecipePage.vue";
 | 
						|
import { usePublicExploreApi } from "~/composables/api/api-client";
 | 
						|
import { useRecipe } from "~/composables/recipes";
 | 
						|
import { Recipe } from "~/lib/api/types/recipe";
 | 
						|
 | 
						|
export default defineComponent({
 | 
						|
  components: { RecipePage },
 | 
						|
  setup() {
 | 
						|
    const { $auth } = useContext();
 | 
						|
    const { isOwnGroup } = useLoggedInState();
 | 
						|
    const { title } = useMeta();
 | 
						|
    const route = useRoute();
 | 
						|
    const router = useRouter();
 | 
						|
    const slug = route.value.params.slug;
 | 
						|
 | 
						|
    let recipe = ref<Recipe | null>(null);
 | 
						|
    if (isOwnGroup.value) {
 | 
						|
      const { recipe: data } = useRecipe(slug);
 | 
						|
      recipe = data;
 | 
						|
    } else {
 | 
						|
      const groupSlug = computed(() => route.value.params.groupSlug || $auth.user?.groupSlug || "")
 | 
						|
      const api = usePublicExploreApi(groupSlug.value);
 | 
						|
      recipe = useAsync(async () => {
 | 
						|
        const { data, error } = await api.explore.recipes.getOne(slug);
 | 
						|
        if (error) {
 | 
						|
          console.error("error loading recipe -> ", error);
 | 
						|
          router.push(`/g/${groupSlug.value}`);
 | 
						|
        }
 | 
						|
 | 
						|
        return data;
 | 
						|
      }, useAsyncKey())
 | 
						|
    }
 | 
						|
 | 
						|
    whenever(
 | 
						|
      () => recipe.value,
 | 
						|
      () => {
 | 
						|
        if (recipe.value) {
 | 
						|
          title.value = recipe.value.name;
 | 
						|
        }
 | 
						|
      },
 | 
						|
    )
 | 
						|
 | 
						|
    return {
 | 
						|
      recipe,
 | 
						|
    };
 | 
						|
  },
 | 
						|
  head: {},
 | 
						|
});
 | 
						|
</script>
 |