renamed models, added mapper for recipes
This commit is contained in:
parent
7a6f5b5bcd
commit
8027fce80d
21 changed files with 164 additions and 61 deletions
|
|
@ -1,9 +1,10 @@
|
|||
import { useParams } from "react-router-dom"
|
||||
import type { Recipe } from "../../types/recipe"
|
||||
import type { RecipeModel } from "../../models/RecipeModel"
|
||||
import { useEffect, useState } from "react"
|
||||
import { fetchRecipe } from "../../api/points/RecipePoint"
|
||||
import { getRecipeEditUrl, getRecipeListUrl } from "../../routes"
|
||||
import ButtonLink from "../basics/ButtonLink"
|
||||
import { mapRecipeDtoToModel } from "../../mappers/recipeMapper"
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -14,9 +15,9 @@ export default function RecipeDetailPage() {
|
|||
// Extract recipe ID from route params
|
||||
const { id } = useParams<{ id: string }>()
|
||||
// the recipe loaded from the backend, don't change this! it's required for scaling
|
||||
const [recipe, setRecipe] = useState<Recipe | null>(null)
|
||||
const [recipe, setRecipe] = useState<RecipeModel | null>(null)
|
||||
// Working copy for re-calculating ingredients
|
||||
const [recipeWorkingCopy, setRecipeWorkingCopy] = useState<Recipe|null>(null)
|
||||
const [recipeWorkingCopy, setRecipeWorkingCopy] = useState<RecipeModel|null>(null)
|
||||
// load recipe data whenever id changes
|
||||
useEffect(() => {
|
||||
const loadRecipe = async () => {
|
||||
|
|
@ -25,7 +26,10 @@ export default function RecipeDetailPage() {
|
|||
// Fetch recipe data when editing an existing one
|
||||
console.log("loading recipe with id", id)
|
||||
const data = await fetchRecipe(id)
|
||||
setRecipe(data)
|
||||
if(data.id != id){
|
||||
throw new Error("Id mismatch when loading recipes: " + id + " requested and " + data.id + " received!");
|
||||
}
|
||||
setRecipe(mapRecipeDtoToModel(data))
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
|
|
@ -125,7 +129,7 @@ export default function RecipeDetailPage() {
|
|||
{/* Action buttons */}
|
||||
<div className="button-group">
|
||||
<ButtonLink
|
||||
to={getRecipeEditUrl(recipe.id)}
|
||||
to={recipe.id !== undefined ? getRecipeEditUrl(recipe.id) : getRecipeListUrl()} // @todo show error instead
|
||||
className="basic-button primary-button-bg primary-button-text"
|
||||
text="Bearbeiten"
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue