added handlers for off campus items

This commit is contained in:
Sunrise
2023-04-30 16:47:43 -04:00
parent 49a59fde65
commit 19343cb9ab
2 changed files with 79 additions and 24 deletions

View File

@@ -134,6 +134,7 @@ const submitGoalHandler = evt => {
//to add an off campus food item or meal to your weekly journal //to add an off campus food item or meal to your weekly journal
const [offCampusInput, setOffCampusInput] = useState({ const [offCampusInput, setOffCampusInput] = useState({
item_name:"",
calories: "", calories: "",
fat_g: "", fat_g: "",
sat_fat_g: "", sat_fat_g: "",
@@ -142,21 +143,39 @@ const submitGoalHandler = evt => {
fiber_g: "", fiber_g: "",
sugar_g: "", sugar_g: "",
protein_g: "", protein_g: "",
sodium_g: "", sodium_mg: "",
potassium_g: "", potassium_mg: "",
cholesterol_g: "", cholesterol_mg: "",
} }
); );
const { calories, fat_g, sat_fat_g, trans_fat_g, carbs_g, fiber_g,sugar_g, protein_g, const {item_name, calories, fat_g, sat_fat_g, trans_fat_g, carbs_g, fiber_g,sugar_g, protein_g,
sodium_g, potassium_g, cholesterol_g, } = offCampusInput sodium_mg, potassium_mg, cholesterol_mg, } = offCampusInput
const changeoffCampusHandler = evt => { const changeOffCampusHandler = evt => {
setOffCampusInput({ ...offCampusInput, [evt.target.name]: [evt.target.value] }) setOffCampusInput({ ...offCampusInput, [evt.target.name]: [evt.target.value] })
} }
const submitoffCampusHandler = evt => { const submitOffCampusHandler = evt => {
evt.preventDefault(); evt.preventDefault();
console.log(offCampusInput)
Axios.post("http://3.219.93.142:8000/api/",
{
calories: calories[0],
trans_fat_g: trans_fat_g[0],
sat_fat_g: sat_fat_g[0],
trans_fat_g: trans_fat_g[0],
carbs_g: carbs_g[0],
fiber_g: fiber_g[0],
sugar_g: sugar_g[0],
protein_g: protein_g[0],
sodium_mg: sodium_mg[0],
potassium_mg: potassium_mg[0],
cholesterol_mg: cholesterol_mg[0]
}).then((response) => {
console.log(response);
console.log(response.status);
})
}; };
@@ -196,17 +215,17 @@ const submitGoalHandler = evt => {
id="total_cal" id="total_cal"
label="Calories" label="Calories"
name="total_cal" name="total_cal"
value={total_cal}
size="small" size="small"
value={total_cal}
onChange={changeGoalHandler} onChange={changeGoalHandler}
/> />
       
<TextField <TextField
id="total_fat" id="total_fat"
label="Fat (g)" label="Fat (g)"
size="small"
name="total_fat" name="total_fat"
value={total_fat} value={total_fat}
size="small"
onChange={changeGoalHandler} onChange={changeGoalHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
@@ -460,81 +479,118 @@ const submitGoalHandler = evt => {
<h3> &nbsp; &nbsp; <h3> &nbsp; &nbsp;
Off-Campus Off-Campus
</h3> </h3>
<form> <form onSubmit={submitOffCampusHandler}>
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
sx={{ paddingBottom: 1 }} sx={{ paddingBottom: 1 }}
id="food-input" id="item_name"
label="Food Item" label="Food Item"
size="small" size="small"
name="item_name"
value={item_name}
onChange={changeOffCampusHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
sx={{ paddingBottom: 1 }} sx={{ paddingBottom: 1 }}
id="calorie-input" id="calories"
label="Calories" label="Calories"
size="small" size="small"
name="calories"
value={calories}
onChange={changeOffCampusHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
id="fat-input" id="fat"
label="Fat (g)" label="Fat (g)"
size="small" size="small"
name="fat_g"
value={fat_g}
onChange={changeOffCampusHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
id="saturated_fat-input" id="sat_fat"
label="Saturated Fat (g)" label="Saturated Fat (g)"
size="small" size="small"
name="sat_fat_g"
value={sat_fat_g}
onChange={changeOffCampusHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
id="trans_fat-input" id="trans_fat"
label="Trans Fat (g)" label="Trans Fat (g)"
size="small" size="small"
name="trans_fat_g"
value={trans_fat_g}
onChange={changeOffCampusHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
id="carbs-input" id="carbs"
label="Carbs (g)" label="Carbs (g)"
size="small" size="small"
name="carbs_g"
value={carbs_g}
onChange={changeOffCampusHandler}
/> />
<br></br> <br></br>
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
id="fiber-input" id="fiber"
label="Fiber (g)" label="Fiber (g)"
size="small" size="small"
name="fiber_g"
value={fiber_g}
onChange={changeOffCampusHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
id="sugar-input" id="sugar"
label="Sugar (g)" label="Sugar (g)"
size="small" size="small"
name="sugar_g"
value={sugar_g}
onChange={changeOffCampusHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
id="protein-input" id="protein"
label="Protein (g)" label="Protein (g)"
size="small" size="small"
name="protein_g"
value={protein_g}
onChange={changeOffCampusHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
id="sodium-input" id="sodium"
label="Sodium (mg)" label="Sodium (mg)"
size="small" size="small"
name="sodium_mg"
value={sodium_mg}
onChange={changeOffCampusHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
id="potassium-input" id="potassium"
label="Potassium (mg)" label="Potassium (mg)"
size="small" size="small"
name="potassium_mg"
value={potassium_mg}
onChange={changeOffCampusHandler}
/> />
&nbsp; &nbsp; &nbsp; &nbsp;
<TextField <TextField
id="cholesterol-input" id="cholesterol"
label="Cholesterol (mg)" label="Cholesterol (mg)"
size="small" size="small"
name="cholesterol_mg"
value={cholesterol_mg}
onChange={changeOffCampusHandler}
/> />
<br></br> <br></br>
<br></br> <br></br>
@@ -546,7 +602,6 @@ const submitGoalHandler = evt => {
size="large"> size="large">
Submit</Button> Submit</Button>
</form> </form>
</div> </div>
</ThemeProvider> </ThemeProvider>

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB