diff --git a/client/src/components/pages/AddRecipe.tsx b/client/src/components/pages/AddRecipe.tsx index 07a2eaa..dd4dc5a 100644 --- a/client/src/components/pages/AddRecipe.tsx +++ b/client/src/components/pages/AddRecipe.tsx @@ -8,26 +8,32 @@ import Protect from "../../util/Protect"; import API from "../../util/API"; import { v4 } from "uuid"; import RichText from "../ui/RichText"; -import { TextareaAutosize, TextField } from "@mui/material"; -// import "/src/sass/pages/AddRecipe.scss"; +import { Autocomplete, TextField } from "@mui/material"; const AddRecipe = () => { const { user, token } = useAuthContext(); const { data, setData } = useSelectorContext(); + // received recipe data const [input, setInput] = useState({ name: '', preptime: '', description: '', authoruserid: '' }) + + // UI state handling const [measurements, setMeasurements] = useState([]); const [ingredientFields, setIngredientFields] = useState>([]); + const [courseData, setCourseData] = useState([]); const [optionCount, setOptionCount] = useState(0); + + // status reporting const [toast, setToast] = useState(<>) // store all ingredients on page mount useEffect(() => { token && (async() => { const ingredients = new API.Ingredient(token); - const _measurements = new API.Measurements(token); + const _dropdowns = new API.Dropdowns(token); const result = await ingredients.getAll(); - const measurementList = await _measurements.getAll(); + const measurementList = await _dropdowns.getAllMeasurements(); + const courseList = await _dropdowns.getAllCourses(); if (result) { setData((prev) => [...prev, ...result]); @@ -36,6 +42,10 @@ const AddRecipe = () => { if (measurementList) { setMeasurements((prev) => [...prev, ...measurementList]); } + + if (courseList) { + setCourseData((prev) => [...prev, ...courseList]); + } })(); }, [token]) @@ -102,8 +112,8 @@ const AddRecipe = () => { } useEffect(() => { - console.log(input); - }, [input]) + console.log(courseData); + }, [courseData]) return ( @@ -123,7 +133,15 @@ const AddRecipe = () => {
- + { courseData.length && + ( + + )} + getOptionLabel={(option) => option.name} + />}
{ data && ( diff --git a/client/src/sass/components/Form.scss b/client/src/sass/components/Form.scss index 3cff7ab..ce1043d 100644 --- a/client/src/sass/components/Form.scss +++ b/client/src/sass/components/Form.scss @@ -28,6 +28,10 @@ width: 85%; } + .MuiAutocomplete-root { + width: 100%; + } + #ingredients-label, #description-label { align-self: flex-start; padding-top: 1rem; diff --git a/client/src/util/API.ts b/client/src/util/API.ts index 139d59a..b97ae03 100644 --- a/client/src/util/API.ts +++ b/client/src/util/API.ts @@ -229,15 +229,20 @@ module API { } } - export class Measurements extends RestController { + export class Dropdowns extends RestController { constructor(token: string) { super(Settings.getAPISTRING() + "/app/dropdown", token); } - override async getAll() { + async getAllMeasurements() { const response = await this.instance.get(this.endpoint + "?datatype=measurement", this.headers); return Promise.resolve(response.data); } + + async getAllCourses() { + const response = await this.instance.get(this.endpoint + "?datatype=course", this.headers); + return Promise.resolve(response.data); + } } }