cleanup, moving around types and functions

This commit is contained in:
Mikayla Dobson
2022-11-19 14:39:36 -06:00
parent 6b09f3f0a4
commit e5e3d9a761
3 changed files with 66 additions and 16 deletions

View File

@@ -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<IRecipe>();
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 (
<Page>
<h1>404 | Not Found</h1>
<p>There's no content here! Technically, you shouldn't have even been able to get here.</p>
<p>So, kudos, I guess!</p>
</Page>
)
}
useEffect(() => {
getRecipeByID();
getRecipeByID(id);
}, [])
return (

View File

@@ -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;
}

View File

@@ -11,4 +11,45 @@ interface ButtonParams extends PortalBase {
export type PageComponent = FC<PortalBase>
export type PanelComponent = FC<PortalBase>
export type ButtonComponent = FC<ButtonParams>
export type ButtonComponent = FC<ButtonParams>
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"]
}