diff --git a/client/src/components/pages/Recipe.tsx b/client/src/components/pages/Recipe.tsx index 9a2d275..66c92a7 100644 --- a/client/src/components/pages/Recipe.tsx +++ b/client/src/components/pages/Recipe.tsx @@ -1,28 +1,25 @@ import { useEffect, useState } from "react"; import { useParams } from "react-router-dom"; import { Page, Panel } from "../ui"; - -interface IRecipe { - id: number - name: string - description: string - preptime: string - datecreated?: string - dateupdated?: string -} +import { IRecipe } from "../../util/types"; +import { getRecipeByID } from "../../util/apiUtils"; export default function Recipe() { - const { id } = useParams(); const [recipe, setRecipe] = useState(); + const { id } = useParams(); - const getRecipeByID = async () => { - const result = await fetch('http://localhost:8080/recipe/' + id) - .then(response => response.json()) - .then(data => setRecipe(data)); + if (!id) { + return ( + +

404 | Not Found

+

There's no content here! Technically, you shouldn't have even been able to get here.

+

So, kudos, I guess!

+
+ ) } useEffect(() => { - getRecipeByID(); + getRecipeByID(id); }, []) return ( diff --git a/client/src/util/apiUtils.ts b/client/src/util/apiUtils.ts index e69de29..fca05d3 100644 --- a/client/src/util/apiUtils.ts +++ b/client/src/util/apiUtils.ts @@ -0,0 +1,12 @@ +const API = import.meta.env.APISTRING || "http://localhost:8080/"; + +// on recipe route +export const getRecipeByID = async (id: string | number) => { + const result = await fetch(API + 'recipe/' + id).then(response => response.json()); + return result; +} + +export const getAllRecipes = async () => { + const result = await fetch(API + 'recipe').then(response => response.json()); + return result; +} \ No newline at end of file diff --git a/client/src/util/types.ts b/client/src/util/types.ts index 0d9bb38..e2f7c86 100644 --- a/client/src/util/types.ts +++ b/client/src/util/types.ts @@ -11,4 +11,45 @@ interface ButtonParams extends PortalBase { export type PageComponent = FC export type PanelComponent = FC -export type ButtonComponent = FC \ No newline at end of file +export type ButtonComponent = FC + +export interface IUser { + id: number + firstname: string + lastname: string + handle: string + email: string + password: string + active: boolean +} + +export interface IRecipe { + id: number + name: string + description?: string + preptime: string + removed: boolean + authoruserid: IUser["id"] +} + +export interface IIngredient { + id: number + name: string + description?: string +} + +export interface ICollection { + id: number + name: string + active: string + ismaincollection: boolean + ownerid: IUser["id"] +} + +export interface IGroceryList { + id: number + name: string + recipes?: IRecipe["id"][] + active: boolean + ownerid: IUser["id"] +} \ No newline at end of file