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,12 +1,12 @@
|
|||
import { useState } from "react"
|
||||
import type { Recipe } from "../../types/recipe"
|
||||
import type { IngredientGroup } from "../../types/ingredientGroup"
|
||||
import type { RecipeModel } from "../../models/RecipeModel"
|
||||
import type { IngredientGroupModel } from "../../models/IngredientGroupModel"
|
||||
import { IngredientGroupListEditor } from "./IngredientGroupListEditor"
|
||||
import Button, { ButtonType } from "../basics/Button"
|
||||
|
||||
type RecipeEditorProps = {
|
||||
recipe: Recipe
|
||||
onSave: (recipe: Recipe) => void
|
||||
recipe: RecipeModel
|
||||
onSave: (recipe: RecipeModel) => void
|
||||
onCancel: () => void
|
||||
}
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ type RecipeEditorProps = {
|
|||
*/
|
||||
export default function RecipeEditor({ recipe, onSave, onCancel }: RecipeEditorProps) {
|
||||
/** draft of the new recipe */
|
||||
const [draft, setDraft] = useState<Recipe>(recipe)
|
||||
const [draft, setDraft] = useState<RecipeModel>(recipe)
|
||||
/** Error list */
|
||||
const [errors, setErrors] = useState<{ title?: boolean; ingredients?: boolean }>({})
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ export default function RecipeEditor({ recipe, onSave, onCancel }: RecipeEditorP
|
|||
* Update ingredients
|
||||
* @param ingredients new ingredients
|
||||
*/
|
||||
const updateIngredientGroupList = (ingredientGroupList: IngredientGroup[]) => {
|
||||
const updateIngredientGroupList = (ingredientGroupList: IngredientGroupModel[]) => {
|
||||
setDraft({ ...draft, ingredientGroupList })
|
||||
}
|
||||
/**
|
||||
|
|
@ -63,7 +63,7 @@ export default function RecipeEditor({ recipe, onSave, onCancel }: RecipeEditorP
|
|||
return Object.keys(newErrors).length === 0
|
||||
}
|
||||
/** Handles saving and ensures that the draft is only saved if valid */
|
||||
const handleSave = (draft: Recipe) => {
|
||||
const handleSave = (draft: RecipeModel) => {
|
||||
if (validate()) {
|
||||
onSave(draft)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue