diff --git a/client/src/components/Sandbox.tsx b/client/src/components/Sandbox.tsx
index fe314e2..53984f7 100644
--- a/client/src/components/Sandbox.tsx
+++ b/client/src/components/Sandbox.tsx
@@ -5,11 +5,7 @@ import { useAuthContext } from "../context/AuthContext";
import { ICollection, IIngredient } from "../schemas";
import { Button, Page } from "./ui";
import API from "../util/API";
-
-interface OptionType {
- value: number
- label: string
-}
+import { OptionType } from "../util/types";
export default function Sandbox() {
const [ingredients, setIngredients] = useState>([]);
diff --git a/client/src/components/pages/AddRecipe.tsx b/client/src/components/pages/AddRecipe.tsx
index dccdb1b..15a43ac 100644
--- a/client/src/components/pages/AddRecipe.tsx
+++ b/client/src/components/pages/AddRecipe.tsx
@@ -1,18 +1,105 @@
import { useCallback, useRef, useEffect, useState, createRef } from "react";
import { useAuthContext } from "../../context/AuthContext";
import { Button, Card, Divider, Form, Page, Panel } from "../ui"
-import { IRecipe } from "../../schemas";
+import { IIngredient, IRecipe } from "../../schemas";
import API from "../../util/API";
+import Creatable from "react-select/creatable";
+import { OptionType } from "../../util/types";
+import { useSelectorContext } from "../../context/SelectorContext";
+import { MultiValue } from "react-select";
const AddRecipe = () => {
const { user, token } = useAuthContext();
- const [input, setInput] = useState({ name: '', preptime: '', description: '', authoruserid: '', ingredients: [] })
- const [toast, setToast] = useState(<>>)
+ const {
+ data, setData, selector, setSelector,
+ options, setOptions, selected, setSelected,
+ onChange, onCreateOption
+ } = useSelectorContext();
+ const [triggerChange, setTriggerChange] = useState(false);
+ const [form, setForm] = useState();
+ const [toast, setToast] = useState(<>>)
+ const [input, setInput] = useState({ name: '', preptime: '', description: '', authoruserid: '' })
+
+ // clear out selector state on page load
+ useEffect(() => {
+ setData(new Array());
+ setSelected(new Array());
+ setOptions(new Array());
+ }, [])
+
+ // store all ingredients on page mount
+ useEffect(() => {
+ token && (async() => {
+ const ingredients = new API.Ingredient(token);
+ const result = await ingredients.getAll();
+
+ if (result) {
+ setData((prev) => [...prev, ...result]);
+
+ // once async data is received, derive its new states
+ setOptions(result.map((each: IIngredient) => {
+ return { label: each.name, value: each.id }
+ }));
+ }
+ })();
+ }, [token])
+
+ useEffect(() => {
+ console.log(selected);
+ }, [selected])
+
+ useEffect(() => {
+ if (data.length) {
+ console.log('caught');
+ // create dropdown from new data
+ const selectorInstance = ) => onChange(selection)}
+ onCreateOption={(input: string) => onCreateOption(input, () => {})}
+ />
+ data.length && setSelector(selectorInstance);
+ setTriggerChange(true);
+ }
+ }, [data, options])
+
+ // once the dropdown data has populated, mount it within the full form
+ useEffect(() => {
+ triggerChange && setForm(
+
"
- }} />
-
+ { form }
{ toast }
diff --git a/client/src/components/pages/Login.tsx b/client/src/components/pages/Login.tsx
index 4ad816a..0cb4f6d 100644
--- a/client/src/components/pages/Login.tsx
+++ b/client/src/components/pages/Login.tsx
@@ -43,7 +43,7 @@ export default function Login() {
-