diff --git a/db_app/src/components/LogMeals.js b/db_app/src/components/LogMeals.js index 2f54aae..2d2adba 100644 --- a/db_app/src/components/LogMeals.js +++ b/db_app/src/components/LogMeals.js @@ -2,33 +2,16 @@ import React,{useState} from 'react'; import {Routes, Route, useNavigate} from 'react-router-dom'; import './Login.css'; import Button from "@mui/material/Button"; -import Card from "@mui/material/Card"; import TextField from "@mui/material/TextField"; -import FormControlLabel from "@mui/material/FormControlLabel"; -import Checkbox from "@mui/material/Checkbox"; -import Link from "@mui/material/Link"; -import Grid from "@mui/material/Grid"; -import Box from "@mui/material/Box"; -import Typography from "@mui/material/Typography"; -import Container from "@mui/material/Container"; import AppBar from '@mui/material/AppBar'; import Toolbar from '@mui/material/Toolbar'; -import IconButton from '@mui/material/IconButton'; -import Avatar from '@mui/material/Avatar'; -import Tooltip from '@mui/material/Tooltip'; -import Menu from '@mui/material/Menu'; -import MenuIcon from '@mui/material/Menu' -import MenuItem from '@mui/material/MenuItem'; import {red, green, lightBlue, lightGreen} from '@mui/material/colors'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import { ReactSession } from 'react-client-session'; -import { Axios } from 'axios'; +import Axios from 'axios'; import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; -import Select, { SelectChangeEvent } from '@mui/material/Select'; -import InputLabel from '@mui/material/InputLabel'; -import FormControl from '@mui/material/FormControl'; -import { Table, TableBody, TableCell, TableContainer,TableHead, TableRow, Paper} from '@mui/material'; +import { Table, TableBody, TableCell, TableContainer,TableHead, TableRow, Paper,Checkbox} from '@mui/material'; const theme = createTheme({ @@ -41,7 +24,7 @@ const theme = createTheme({ }, }); -function LogMeals() { +function MyPlan() { const navigate = useNavigate(); @@ -65,12 +48,15 @@ const logout = () => { } const Log = () => { - navigate('/LogMeals') - } - - const Progress = () => { - navigate('/ThisWeek') - } + navigate('/LogMeals') +} + +const Progress = () => { + navigate('/ThisWeek') +} + + + //get the start of each week and reformat to Oracle date type function weekStart(){ var date_str = new Date(); @@ -96,17 +82,17 @@ const net_id = ReactSession.get("net_id"); //to set nutritional goal for the week const [goalInput, setGoalInput] = useState({ - total_cal: "", - total_fat: "", - total_sat_fat: "", - total_trans_fat: "", - total_carbs: "", - total_fiber: "", - total_sugar: "", - total_protein: "", - total_sodium: "", - total_potassium: "", - total_cholesterol: "", + total_cal: 0, + total_fat: 0, + total_sat_fat: 0, + total_trans_fat: 0, + total_carbs: 0, + total_fiber: 0, + total_sugar: 0, + total_protein: 0, + total_sodium: 0, + total_potassium: 0, + total_cholesterol: 0, } ); @@ -120,57 +106,138 @@ const changeGoalHandler = evt =>{ const submitGoalHandler = evt => { evt.preventDefault(); console.log(goalInput) - Axios.post("http://3.219.93.142:8000/api/", + console.log(net_id) + console.log(weekStart()) + Axios.post("http://3.219.93.142:8000/api/goal", { - 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] + net_id: net_id, + week_date: weekStart(), + total_cal: Number(total_cal[0]), + total_fat: Number(total_fat[0]), + total_sat_fat: Number(total_sat_fat[0]), + total_trans_fat: Number(total_trans_fat[0]), + total_carbs: Number(total_carbs[0]), + total_fiber: Number(total_fiber[0]), + total_sugar: Number(total_sugar[0]), + total_protein: Number(total_protein[0]), + total_sodium: Number(total_sodium[0]), + total_potassium: Number(total_potassium[0]), + total_cholesterol: Number(total_cholesterol[0]) }).then((response) => { console.log(response); console.log(response.status); }) }; +//to find a food item from an on campus location to your weekly journal +const [keyword, setKeyword] = useState({ + search_term:"" +}) + +const [searchItems, setSearchItems] = useState([{}]); + +const{search_term} = keyword + +const removeItem = (index) => { + setSearchItems([ + ...searchItems.slice(0, index), + ...searchItems.slice(index + 1) + ]); + +} + +function handleCheck (i) { + console.log(i); + if (searchItems.indexOf(i) > -1){ + //get index and delete + var index = searchItems.indexOf(i) + removeItem(index); + console.log(`removed ${i}`); + + } + + else{ + setSearchItems(searchItems => [...searchItems, i]); + console.log(`added ${i}`); + } + +} + + +const changeSearchHandler = evt => { + setKeyword({ ...keyword, [evt.target.name]: [evt.target.value] }) +} + +const submitSearchHandler = evt => { + evt.preventDefault(); + console.log(search_term) + console.log(net_id) + Axios.post("http://3.219.93.142:8000/api/menu_search", + { + search_term:search_term[0] + }).then((response) => { + console.log(response); + console.log(response.status); + console.log(response.data); + setSearchItems(response.data); + }) +}; + //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: "", + item_name:"", + amount: 0, + calories: 0, + fat_g: 0, + sat_fat_g: 0, + trans_fat_g: 0, + carbs_g: 0, + fiber_g: 0, + sugar_g: 0, + protein_g: 0, + sodium_mg: 0, + potassium_mg: 0, + cholesterol_mg: 0, } ); - 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 {item_name, amount, calories, fat_g, sat_fat_g, trans_fat_g, carbs_g, fiber_g,sugar_g, protein_g, + sodium_mg, potassium_mg, cholesterol_mg} = offCampusInput - const changeoffCampusHandler = evt => { + const changeOffCampusHandler = evt => { setOffCampusInput({ ...offCampusInput, [evt.target.name]: [evt.target.value] }) } - const submitoffCampusHandler = evt => { + const submitOffCampusHandler = evt => { evt.preventDefault(); + console.log(offCampusInput) + console.log(net_id) + Axios.post("http://3.219.93.142:8000/api/week_plan", + { + net_id: net_id, + item_name: item_name[0], + amount: Number(amount[0]), + calories: Number(calories[0]), + fat_g: Number(fat_g[0]), + sat_fat_g: Number(sat_fat_g[0]), + trans_fat_g: Number(trans_fat_g[0]), + carbs_g: Number(carbs_g[0]), + fiber_g: Number(fiber_g[0]), + sugar_g: Number(sugar_g[0]), + protein_g: Number(protein_g[0]), + sodium_mg: Number(sodium_mg[0]), + potassium_mg: Number(potassium_mg[0]), + cholesterol_mg: Number(cholesterol_mg[0]) + }).then((response) => { + console.log(response); + console.log(response.status); + }) }; - return ( - + - - + + + + - + - - +
-

  Your Plan

-

   Goal for the week of:

- -
-     - -     - -     - -     - -     - -

-     - -     - -     - -     - -     - -     - -

-

-     - - - -
-

- -
-

-     - So Far This Week: -

- -

-     - Foods Eaten -

- - - - - - Food - Calories - Fat (g) - Saturated Fat (g) - TransFat (g) - Carbs (g) - Fiber (g) - Sugar (g) - Protein (g) - Sodium (mg) - Potassium (mg) - Cholesterol (mg) - - - - - - - - - - - - - - - - - - -
-
- -

-     - Weekly Totals -

- - - - - - Calories - Fat (g) - Saturated Fat (g) - TransFat (g) - Carbs (g) - Fiber (g) - Sugar (g) - Protein (g) - Sodium (mg) - Potassium (mg) - Cholesterol (mg) - - - - - - - - - - - - - - - - - -
-
- -

- -     - - -     - -       - -     - -     - -       - -       - -       - -           - -           - - -
- -
-

-     +

+   Add to Food Journal -

+

    On-Campus

-
-     - - Dining Location - - - +         @@ -481,84 +304,190 @@ const submitGoalHandler = evt => { Search + + + + + + + Add? + Eatery + Item Name + Serving Size + + + + + + {searchItems.map((searchitem, i) => { + console.log(i); + return( + + + + + handleCheck(searchitem.item_id)} + /> + + + {searchitem.item_name} + + + {searchitem.eatery_id} + {searchitem.item_name} + {searchitem.serving_size} + + ) + })} + +
+
+
+ +

    Off-Campus

-
+     -     - -     - -     - -     - -     -

    +     + +     + +     + +     + + +     + +

+     +                    



@@ -569,12 +498,12 @@ const submitGoalHandler = evt => { variant="contained" size="large"> Submit - - +
+
); } - export default LogMeals; \ No newline at end of file + export default MyPlan; \ No newline at end of file diff --git a/db_app/src/components/Menus.js b/db_app/src/components/Menus.js index 6fee801..800ffaf 100644 --- a/db_app/src/components/Menus.js +++ b/db_app/src/components/Menus.js @@ -109,7 +109,7 @@ const menuExpansion = () => { - - - - - - - - - - -
-

  Your Plan

-

   Goal for the week of:

- -
-     - -     - -     - -     - -     - -

-     - -     - -     - -     - -     - -     - -

-

-     - - - -
-

-

-     - So Far This Week: -

+

+   + Past plans: +

-

-     - Foods Eaten -

+ @@ -371,205 +242,12 @@ const submitGoalHandler = evt => {
-

-     - Weekly Totals -

+
- - - - - Calories - Fat (g) - Saturated Fat (g) - TransFat (g) - Carbs (g) - Fiber (g) - Sugar (g) - Protein (g) - Sodium (mg) - Potassium (mg) - Cholesterol (mg) - - - - - - - - - - - - - - - - - -
-
- -

- -     - - -     - -       - -     - -     - -       - -       - -       - -           - -           - - - - -
-

-     - Add to Food Journal -

-

    - On-Campus -

-
-     - - Dining Location - - - -     - - -     - - - -

    - Off-Campus -

-
-     - -     - -     - -     - -     - -     - -

-     - -     - -     - -     - -     - -     - -

-

-     - - - - -
+ ); } - export default ThisWeek; \ No newline at end of file + export default Past; \ No newline at end of file diff --git a/db_app/src/components/Plan.js b/db_app/src/components/Plan.js index 2709724..f6dee47 100644 --- a/db_app/src/components/Plan.js +++ b/db_app/src/components/Plan.js @@ -1,4 +1,4 @@ -import React,{useState} from 'react'; +import React,{useState, useEffect} from 'react'; import {Routes, Route, useNavigate} from 'react-router-dom'; import './Login.css'; import Button from "@mui/material/Button"; @@ -11,7 +11,7 @@ import { ReactSession } from 'react-client-session'; import Axios from 'axios'; import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; -import { Table, TableBody, TableCell, TableContainer,TableHead, TableRow, Paper} from '@mui/material'; +import { Table, TableBody, TableCell, TableContainer,TableHead, TableRow, Paper,Checkbox} from '@mui/material'; const theme = createTheme({ @@ -19,7 +19,6 @@ const theme = createTheme({ primary: { main: lightGreen[700], apple: red[500], - main2: '#588157', }, }, @@ -56,7 +55,10 @@ const Progress = () => { navigate('/ThisWeek') } - +const [week, setWeek] = useState(); +const displayWeek = () => { + setWeek(() => weekStart()); +} //get the start of each week and reformat to Oracle date type function weekStart(){ @@ -135,8 +137,36 @@ const [keyword, setKeyword] = useState({ search_term:"" }) +const [searchItems, setSearchItems] = useState([{}]); + const{search_term} = keyword +const removeItem = (index) => { + setSearchItems([ + ...searchItems.slice(0, index), + ...searchItems.slice(index + 1) + ]); + +} + +function handleCheck (i) { + console.log(i); + if (searchItems.indexOf(i) > -1){ + //get index and delete + var index = searchItems.indexOf(i) + removeItem(index); + console.log(`removed ${i}`); + + } + + else{ + setSearchItems(searchItems => [...searchItems, i]); + console.log(`added ${i}`); + } + +} + + const changeSearchHandler = evt => { setKeyword({ ...keyword, [evt.target.name]: [evt.target.value] }) } @@ -152,6 +182,7 @@ const submitSearchHandler = evt => { console.log(response); console.log(response.status); console.log(response.data); + setSearchItems(response.data); }) }; @@ -206,6 +237,12 @@ const submitSearchHandler = evt => { console.log(response.status); }) }; + + useEffect(() => { + displayWeek() + console.log('week calculated') + }, []); + return ( @@ -232,8 +269,8 @@ const submitSearchHandler = evt => { - - + + - - - - - - - Food - Calories - Fat (g) - Saturated Fat (g) - TransFat (g) - Carbs (g) - Fiber (g) - Sugar (g) - Protein (g) - Sodium (mg) - Potassium (mg) - Cholesterol (mg) - - - - - - - - - - - - - - - - - - -
-
- - -

    - Off-Campus -

-
-     - -

-     - -     - -     - -     - -     - - -     - -

-     - -     - -     - -     - -     - -     - -

-

-     - - - - -
); diff --git a/db_app/src/components/ThisWeek.js b/db_app/src/components/ThisWeek.js index c1e43f7..fc0f7d3 100644 --- a/db_app/src/components/ThisWeek.js +++ b/db_app/src/components/ThisWeek.js @@ -1,4 +1,4 @@ -import React,{useState} from 'react'; +import React,{useState, useEffect} from 'react'; import {Routes, Route, useNavigate} from 'react-router-dom'; import './Login.css'; import Button from "@mui/material/Button"; @@ -22,7 +22,7 @@ import MenuItem from '@mui/material/MenuItem'; import {red, green, lightBlue, lightGreen} from '@mui/material/colors'; import { ThemeProvider, createTheme } from '@mui/material/styles'; import { ReactSession } from 'react-client-session'; -import { Axios } from 'axios'; +import Axios from 'axios'; import Chip from '@mui/material/Chip'; import Stack from '@mui/material/Stack'; import Select, { SelectChangeEvent } from '@mui/material/Select'; @@ -167,6 +167,42 @@ const submitGoalHandler = evt => { evt.preventDefault(); }; + const [pastItems, setPastItems] = useState([{}]); + const makeURL = (net_id) => `http://3.219.93.142:8000/api/week_progress/${net_id}`; + + const getHistory = () => { + const net_id = ReactSession.get("net_id"); + const url_to_query = makeURL(net_id); + Axios.get(url_to_query).then((response) => { + console.log(response.data); + setPastItems(response.data); + }); + + } + useEffect(() => { + getHistory() + console.log('History in') + }, []) + + const [sum, setSum] = useState([{}]); + const sumURL = (net_id) => `http://3.219.93.142:8000/api/week_sum/${net_id}`; + + const getSum = () => { + const net_id = ReactSession.get("net_id"); + const url_to_query = sumURL(net_id); + Axios.get(url_to_query).then((response) => { + console.log(response.data); + setSum(response.data); + }); + + } + useEffect(() => { + getHistory() + console.log('History in') + getSum() + console.log('Sum in') + }, []) + return ( @@ -209,216 +245,132 @@ const submitGoalHandler = evt => { -
-

  Your Plan

-

   Goal for the week of:

- -
-     - -     - -     - -     - -     - -

-     - -     - -     - -     - -     - -     - -

-

-     - - - -
-

-

-     +

+   So Far This Week: -

+

    Foods Eaten

- - + + +
- - Food - Calories - Fat (g) - Saturated Fat (g) - TransFat (g) - Carbs (g) - Fiber (g) - Sugar (g) - Protein (g) - Sodium (mg) - Potassium (mg) - Cholesterol (mg) + + + + Food + Calories + Fat (g) + Saturated Fat (g) + TransFat (g) + Carbs (g) + Fiber (g) + Sugar (g) + Protein (g) + Sodium (mg) + Potassium (mg) + Cholesterol (mg) - - - - - - - - - - - - - + + {pastItems.map((pastitem, i) => { + console.log(i); + return( + + + + {pastitem.item_name} + + + {pastitem.calories} + {pastitem.fat_g} + {pastitem.sat_fat_g} + {pastitem.trans_fat_g} + {pastitem.carbs_g} + {pastitem.fiber_g} + {pastitem.sugar_g} + {pastitem.protein_g} + {pastitem.sodium_mg} + {pastitem.potassium_mg} + {pastitem.cholesterol_mg} + ) + })}
+ +

    Weekly Totals

- - + + +
- - Calories - Fat (g) - Saturated Fat (g) - TransFat (g) - Carbs (g) - Fiber (g) - Sugar (g) - Protein (g) - Sodium (mg) - Potassium (mg) - Cholesterol (mg) + + + + Calories + Fat (g) + Saturated Fat (g) + TransFat (g) + Carbs (g) + Fiber (g) + Sugar (g) + Protein (g) + Sodium (mg) + Potassium (mg) + Cholesterol (mg) - - - - - - - - - - - - + + + + + + {sum.calories} + {sum.fat_g} + {sum.sat_fat_g} + {sum.trans_fat_g} + {sum.carbs_g} + {sum.fiber_g} + {sum.sugar_g} + {sum.protein_g} + {sum.sodium_mg} + {sum.potassium_mg} + {sum.cholesterol_mg}
+

- +

    + At a glance +

+ + +                 @@ -442,136 +394,7 @@ const submitGoalHandler = evt => {
-
-

-     - Add to Food Journal -

-

    - On-Campus -

-
-     - - Dining Location - - - -     - - -     - - - -

    - Off-Campus -

-
-     - -     - -     - -     - -     - -     - -

-     - -     - -     - -     - -     - -     - -

-

-     - - - - -
+
); diff --git a/db_app/src/components/images/back.jpg b/db_app/src/components/images/back.jpg index dd6478a..05c88f6 100644 Binary files a/db_app/src/components/images/back.jpg and b/db_app/src/components/images/back.jpg differ