diff --git a/client/src/components/recipe/RecipeDetail.tsx b/client/src/components/recipe/RecipeDetail.tsx
index 572e1a9..6e310ff 100644
--- a/client/src/components/recipe/RecipeDetail.tsx
+++ b/client/src/components/recipe/RecipeDetail.tsx
@@ -22,7 +22,7 @@ export function RecipeDetail({ recipe }: RecipeDetailProps) {
))}
- {recipe.averageRating !== null ?(
+ {recipe.averageRating != null ?(
= gql`
query GetRecipes($page: Int, $pageSize: Int) {
recipes(page: $page, pageSize: $pageSize) {
@@ -14,4 +17,31 @@ export const GET_RECIPES: TypedDocumentNode
servings
}
}
+`
+export const GET_RECIPE: TypedDocumentNode = gql`
+ query GetRecipe($id: ID!) {
+ recipe(id: $id) {
+ id
+ title
+ description
+ prepTimeMinutes
+ servings
+ imageUrl
+ tags {
+ id
+ name
+ }
+ ingredients {
+ id
+ amount
+ unit
+ name
+ }
+ steps{
+ id
+ order
+ instruction
+ }
+ }
+ }
`
\ No newline at end of file
diff --git a/client/src/routes/RecipeDetailPage.tsx b/client/src/routes/RecipeDetailPage.tsx
index 2a0060d..e676eaf 100644
--- a/client/src/routes/RecipeDetailPage.tsx
+++ b/client/src/routes/RecipeDetailPage.tsx
@@ -1,11 +1,25 @@
import { useParams } from 'react-router';
-import { recipes } from '../mocks/recipes';
import { RecipeDetail } from '../components/recipe/RecipeDetail';
+import { useQuery } from '@apollo/client/react';
+import { GET_RECIPE } from '../graphql/recipes';
// Placeholder for en oppskrift. Henter id fra URL-en. som /recipes/5 gir id = 5
export default function RecipeDetailPage() {
const { id } = useParams();
- const recipe = recipes.find((r) => r.id === id);
+ const { data, loading, error } = useQuery(GET_RECIPE, {
+ variables: { id: id ?? '' },
+ skip: !id,
+ });
+
+ if(loading) {
+ return Laster oppskriften...
+ }
+
+ if (error) {
+ return Kunne ikke hente oppskriften. Prøv igjen senere.
+ }
+
+ const recipe = data?.recipe;
if (!recipe) {
return Fant ikke oppskriften.
}