From 9c525856882ade2c820000d9a2d7357138d36d2f Mon Sep 17 00:00:00 2001 From: Sunrise Date: Sun, 30 Apr 2023 15:21:19 -0400 Subject: [PATCH 1/2] added handlers for weekly goal --- db_app/src/components/Plan.js | 75 ++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 19 deletions(-) diff --git a/db_app/src/components/Plan.js b/db_app/src/components/Plan.js index 13118b2..cc7dd8f 100644 --- a/db_app/src/components/Plan.js +++ b/db_app/src/components/Plan.js @@ -87,9 +87,7 @@ function weekStart(){ const net_id = ReactSession.get("net_id"); //to set nutritional goal for the week -const [goalInput, setGoalInput] = useReducer( - (state, newState) => ({ ...state, ...newState }), - { +const [goalInput, setGoalInput] = useState({ total_cal: "", total_fat: "", total_sat_fat: "", @@ -104,12 +102,18 @@ const [goalInput, setGoalInput] = useReducer( } ); +const{total_cal, total_fat, total_sat_fat, total_trans_fat, total_carbs, total_fiber, + total_sugar, total_protein, total_sodium, total_potassium, total_cholesterol} = goalInput -const handleSubmit = evt => { - let data = {goalInput} +const changeGoalHandler = evt =>{ + setGoalInput({...goalInput, [evt.target.name]: [evt.target.value] }) +} + +const submitGoalHandler = evt => { + evt.preventDefault(); Axios.post() -} +}; return ( @@ -140,74 +144,107 @@ const handleSubmit = evt => {

  Your Plan

   Goal for the week of:

-
+                    

                       



From 780a66c6b50454013eb501288e8ef79956e4c68a Mon Sep 17 00:00:00 2001 From: Sunrise Date: Sun, 30 Apr 2023 15:46:16 -0400 Subject: [PATCH 2/2] added axios post for weekly goal --- db_app/src/components/Plan.js | 53 ++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/db_app/src/components/Plan.js b/db_app/src/components/Plan.js index cc7dd8f..eca3322 100644 --- a/db_app/src/components/Plan.js +++ b/db_app/src/components/Plan.js @@ -1,4 +1,4 @@ -import React,{useState, useReducer} from 'react'; +import React,{useState} from 'react'; import {Routes, Route, useNavigate} from 'react-router-dom'; import './Login.css'; import Button from "@mui/material/Button"; @@ -111,9 +111,54 @@ const changeGoalHandler = evt =>{ const submitGoalHandler = evt => { evt.preventDefault(); - - Axios.post() + console.log(goalInput) + Axios.post("http://3.219.93.142:8000/api/", + { + total_cal: total_cal[0], + total_fat: total_fat[0], + total_sat_fat: total_sat_fat[0], + total_trans_fat: total_trans_fat[0], + total_carbs: total_carbs[0], + total_fiber: total_fiber[0], + total_sugar: total_sugar[0], + total_protein: total_protein[0], + total_sodium: total_sodium[0], + total_potassium: total_potassium[0], + total_cholesterol: total_cholesterol[0] + }).then((response) => { + console.log(response); + console.log(response.status); + }) }; + + +//to add an off campus food item or meal to your weekly journal + const [offCampusInput, setOffCampusInput] = useState({ + calories: "", + fat_g: "", + sat_fat_g: "", + trans_fat_g: "", + carbs_g: "", + fiber_g: "", + sugar_g: "", + protein_g: "", + sodium_g: "", + potassium_g: "", + cholesterol_g: "", + } + ); + + const { calories, fat_g, sat_fat_g, trans_fat_g, carbs_g, fiber_g,sugar_g, protein_g, + sodium_g, potassium_g, cholesterol_g, } = offCampusInput + + const changeoffCampusHandler = evt => { + setOffCampusInput({ ...offCampusInput, [evt.target.name]: [evt.target.value] }) + } + + const submitoffCampusHandler = evt => { + evt.preventDefault(); + }; + return ( @@ -274,7 +319,7 @@ const submitGoalHandler = evt => { - Food + Food Calories Fat (g) Saturated Fat (g)