diff --git a/client/src/graphql/profile.ts b/client/src/graphql/profile.ts new file mode 100644 index 0000000..e885df6 --- /dev/null +++ b/client/src/graphql/profile.ts @@ -0,0 +1,15 @@ +import { gql, type TypedDocumentNode } from '@apollo/client'; +import type { Recipe } from '../types/recipe'; + +// oppskriftene innlogget bruker har laget +export const MY_RECIPES: TypedDocumentNode<{ myRecipes: Recipe[] }> = gql` + query MyRecipes { + myRecipes { + id + imageUrl + title + prepTimeMinutes + servings + } + } +`; diff --git a/client/src/routes/ProfilePage.tsx b/client/src/routes/ProfilePage.tsx index 98d8c9a..649c85c 100644 --- a/client/src/routes/ProfilePage.tsx +++ b/client/src/routes/ProfilePage.tsx @@ -3,6 +3,9 @@ import { Link, useNavigate } from 'react-router'; import { Button } from '../components/ui/Button'; import { PreferencesForm } from '../components/profile/PreferencesForm'; import { useCurrentUser } from '../lib/useCurrentUser'; +import { useQuery } from '@apollo/client/react'; +import { RecipeList } from '../components/recipe/RecipeList'; +import { MY_RECIPES } from '../graphql/profile'; type Tab = 'preferences' | 'favorites' | 'shared' | 'sharedWithMe'; type RecipeTab = Exclude; @@ -37,10 +40,16 @@ export default function ProfilePage() { const navigate = useNavigate(); const [activeTab, setActiveTab] = useState('preferences'); + // oppskriftene brukeren har laget og den henter på nytt hver gang siden åpnes på nytt + const { data: myRecipesData } = useQuery(MY_RECIPES, { + fetchPolicy: 'cache-and-network', + }); + // RequireAuth sørger for at user finnes if (!user) return null; const isGuest = user.authProvider === 'GUEST'; + const myRecipes = myRecipesData?.myRecipes ?? []; // på desktop vises preferanser alltid til venstre, så høyre side viser favoritter i stedet const desktopTab: RecipeTab = @@ -80,7 +89,7 @@ export default function ProfilePage() { {/* TODO: hent ekte tall fra backend */}