From c04674fa74c2e43535181431aef5d891f8839619 Mon Sep 17 00:00:00 2001 From: Kevin Hoerr Date: Sun, 14 Aug 2022 21:35:45 +0000 Subject: Merge planner code (#3) Reviewed-on: https://git.submelon.dev/kjhoerr/pantry/pulls/3 --- src/components/add-item.tsx | 101 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/components/add-item.tsx (limited to 'src/components/add-item.tsx') diff --git a/src/components/add-item.tsx b/src/components/add-item.tsx new file mode 100644 index 0000000..9c4a998 --- /dev/null +++ b/src/components/add-item.tsx @@ -0,0 +1,101 @@ +import { ChangeEvent, useMemo, useState } from "react"; +import { Button, Form, InputOnChangeData, Segment } from "semantic-ui-react"; +import { PantryItem } from "../model"; + +const defaultPantryItem = () => + ({ + name: "", + description: "", + quantity: 1, + quantityUnitType: "oz", + } as PantryItem); + +interface AddItemProps { + addItem: (item: PantryItem) => Promise; +} + +const AddItem = ({ addItem }: AddItemProps) => { + const [additionItem, setAdditionItem] = useState(); + const [additionItemLoading, setAdditionItemLoading] = useState(false); + + const handleItemChange = ( + _: ChangeEvent, + { name, value }: InputOnChangeData + ) => + setAdditionItem((item) => ({ + ...(item !== undefined ? item : defaultPantryItem()), + [name]: value, + })); + + const newItem = useMemo( + () => additionItem ?? defaultPantryItem(), + [additionItem] + ); + + return ( + <> + + + + ); +}; + +export default AddItem; -- cgit