diff --git a/db_app/src/App.js b/db_app/src/App.js index 0cbd162..3d06b0f 100644 --- a/db_app/src/App.js +++ b/db_app/src/App.js @@ -4,6 +4,9 @@ import CreateAccount from "./components/CreateAccount"; import Menus from "./components/Menus"; import Plan from "./components/Plan"; import MenuExpansion from "./components/MenuExpansion"; +import LogMeals from "./components/LogMeals"; +import ThisWeek from "./components/ThisWeek"; +import Past from "./components/Past" import { ReactSession } from 'react-client-session'; import { @@ -24,6 +27,9 @@ function App() { }> }> }> + }> + }> + }> ); diff --git a/db_app/src/components/CreateAccount.js b/db_app/src/components/CreateAccount.js index 9d20f31..d3bb37c 100644 --- a/db_app/src/components/CreateAccount.js +++ b/db_app/src/components/CreateAccount.js @@ -27,12 +27,14 @@ const theme = createTheme({ function CreateAccount() { - const navigate = useNavigate(); + //Navigate to login + const navigate = useNavigate(); const navigateLogin = () => { navigate('/'); } + //State variable for account data const [data,setData] = useState({ net_id:"", password:"", @@ -40,22 +42,22 @@ function CreateAccount() { last_name:"", }) + //Variable for account data const {net_id, password, first_name, last_name} = data; + //Change handler for form const changeHandler = e => { setData({...data,[e.target.name]:[e.target.value]}); } + //Submit handler for form const submitHandler = e => { e.preventDefault(); - console.log(data); - console.log(net_id[0]) - console.log(password[0]) - console.log(first_name[0]) - console.log(last_name[0]) createAccount(); + navigateLogin(); } + //Sends post request with account credentials to server const createAccount = () => { Axios.post("http://3.219.93.142:8000/api/signup", {net_id: net_id[0], password: password[0], first_name: first_name[0], last_name: last_name[0]}).then((response) => { console.log(response); diff --git a/db_app/src/components/LogMeals.js b/db_app/src/components/LogMeals.js new file mode 100644 index 0000000..3d4a38a --- /dev/null +++ b/db_app/src/components/LogMeals.js @@ -0,0 +1,482 @@ +import React,{useState} from 'react'; +import {Routes, Route, useNavigate} from 'react-router-dom'; +import './Login.css'; +import Button from "@mui/material/Button"; +import TextField from "@mui/material/TextField"; +import AppBar from '@mui/material/AppBar'; +import Toolbar from '@mui/material/Toolbar'; +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 Chip from '@mui/material/Chip'; +import Stack from '@mui/material/Stack'; +import { Table, TableBody, TableCell, TableContainer,TableHead, TableRow, Paper,Checkbox} from '@mui/material'; + + +const theme = createTheme({ + palette: { + primary: { + main: lightGreen[700], + apple: red[500], + }, + + }, + }); + +function MyPlan() { + + const navigate = useNavigate(); + + const Home = () => { + navigate('/Plan'); + } + const Menus = () => { + navigate('/Menus'); + } + const Past = () => { + navigate('/Past'); +} +const navigateLogin = () => { + navigate('/'); +} + +const logout = () => { + ReactSession.set("net_id", ""); + navigateLogin(); + +} + +const Log = () => { + 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(); + const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] + var weekday = days[date_str.getDay()] + + if (weekday != 'Sunday'){ + return; + } + + var date_str = new Date(); + var curr_day = String(date_str.getDate()).padStart(2, '0'); + const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']; + + var curr_month = months[date_str.getMonth()]; + var curr_year = String(date_str.getFullYear()); + var db_date = curr_day + '-' + curr_month + '-' + curr_year.slice(2); + + return db_date; +} + +const net_id = ReactSession.get("net_id"); + + + +//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 [sendItems, setSendItems] = useState([]) + +const sendToPlan = () => { + console.log(sendItems); + Axios.post('http://3.219.93.142:8000/api/week_meals', {net_id: ReactSession.get("net_id"), item_list: sendItems,}).then((response) => { + console.log(response); + }); + Progress(); +} + + +const{search_term} = keyword + +const removeItem = (index) => { + setSendItems([ + ...sendItems.slice(0, index), + ...sendItems.slice(index + 1) + ]); + +} + +function handleCheck (i) { + console.log(i); + if (sendItems.indexOf(i) > -1){ + //get index and delete + var index = sendItems.indexOf(i) + removeItem(index); + console.log(`removed ${i}`); + + } + + else{ + setSendItems(sendItems => [...sendItems, 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('Data:') + console.log(response.data.results); + setSearchItems(response.data.results); + }) +}; + + +//to add an off campus food item or meal to your weekly journal + const [offCampusInput, setOffCampusInput] = useState({ + 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 {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 => { + setOffCampusInput({ ...offCampusInput, [evt.target.name]: [evt.target.value] }) + } + + 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 ( + + + + + + + + + + + + + + + + + + + + + + +
+

+   + Add to Food Journal +

+

    + On-Campus +

+
+     + + +     + + + + + + + + + + + Add? + Eatery + Item Name + Serving Size + + + + + + {searchItems.map((searchitem, i) => { + console.log(i); + return( + + + + + handleCheck(searchitem.item_id)} + /> + + + {searchitem.eatery_id} + {searchitem.item_name} + {searchitem.serving_size} + + ) + })} + +
+
+
+ + +

    + Off-Campus +

+
+     + +

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

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

+

+     + + + +
+ +
+ + ); + } + + export default MyPlan; \ No newline at end of file diff --git a/db_app/src/components/Login.css b/db_app/src/components/Login.css index 6497ac9..621099b 100644 --- a/db_app/src/components/Login.css +++ b/db_app/src/components/Login.css @@ -30,4 +30,12 @@ position:fixed; .bar{ margin-bottom: 15px; +} + +.background_green{ + background-color: green; +} + +.background_red{ + background-color: red; } \ No newline at end of file diff --git a/db_app/src/components/Login.js b/db_app/src/components/Login.js index a42c005..f77ac44 100644 --- a/db_app/src/components/Login.js +++ b/db_app/src/components/Login.js @@ -29,6 +29,8 @@ const theme = createTheme({ export function Login() { + + //Navigate functions const navigate = useNavigate(); const navigateCreateAccount = () => { @@ -37,54 +39,53 @@ export function Login() { const navigateHome = () => { navigate('/Plan'); - } + } -const [data,setData] = useState({ + //State variable for login data + const [data,setData] = useState({ net_id:"", password:"" }) + //Variable for login data const {net_id,password} = data; + //Change handler for login form const changeHandler = e => { setData({...data,[e.target.name]:[e.target.value]}); } + //Submit handler for login form const submitHandler = e => { e.preventDefault(); login(); } -const setSession = () => { + //Set session variable for netid + const setSession = () => { ReactSession.set("net_id", net_id[0]); -} + } +//Send http request to log user in + const login = () => { + Axios.post("http://3.219.93.142:8000/api/auth", {net_id: net_id[0], password: password[0],}).then((response) => { + console.log(response); + console.log(response.status); + if (response.status === 200){ + setSession(); + navigateHome(); + } -const getHello = () => { - Axios.get("http://3.219.93.142:8000/").then((response) => { - console.log(response.data); - }); -}; - -const login = () => { - Axios.post("http://3.219.93.142:8000/api/auth", {net_id: net_id[0], password: password[0],}).then((response) => { - console.log(response); - console.log(response.status); - if (response.status === 200){ - setSession(); - navigateHome(); - } - - }); -}; + }); + }; return ( -
+
{ - return ReactSession.get("eatery"); - } - - function MenuExpansion() { - const navigate = useNavigate(); + //Navigate function + const navigate = useNavigate(); const Home = () => { navigate('/Plan'); } - const Menus = () => { + const Menus = () => { navigate('/Menus'); } const Past = () => { navigate('/Past'); -} -const navigateLogin = () => { + } + const navigateLogin = () => { navigate('/'); + } + +//Format api all url based on eatery clicked +const makeEateryUrl = (eatery) => `http://3.219.93.142:8000/api/eatery/${eatery}`; +const getEatery = () => { + return ReactSession.get("eatery"); } -const makeEateryUrl = (eatery) => `http://3.219.93.142:8000/eatery/${eatery}`; - +//Http request to get menu items const getMenu = () => { - const eatery_to_query = getEatery(); - Axios.get(makeEateryUrl(eatery_to_query)).then((response) => { - console.log(response.data); - }); -}; +const eatery_to_query = getEatery(); + Axios.get(makeEateryUrl(eatery_to_query)).then((response) => { + console.log(response.data); + setmenuItems(response.data); +}); + +} +//State variables for menu items and for items to add to plan +const [menuItems, setmenuItems] = useState([{}]); +const [toAdd, setToAdd] = useState([]); -return( +//Remove an item from the to be added +const removeItem = (index) => { + setToAdd([ + ...toAdd.slice(0, index), + ...toAdd.slice(index + 1) + ]); +} + +//Checkbox handler +function handleCheck (i) { + console.log(i); + if (toAdd.indexOf(i) > -1){ + //get index and delete + var index = toAdd.indexOf(i) + removeItem(index); + console.log(`removed ${i}`); + + } + + else{ + setToAdd(toAdd => [...toAdd, i]); + console.log(`added ${i}`); + } + +} + +//Http request to send checked items to plan +const sendToPlan = () => { + Axios.post('http://3.219.93.142:8000/api/week_meals', {net_id: ReactSession.get("net_id"), item_list: toAdd,}).then((response) => { + console.log(response); + }); + + } + +//Run get menu on page load +useEffect(() => { + getMenu() + console.log('Menu in') +}, []) + + + return ( @@ -92,10 +148,68 @@ return( - + + +

    Menu Items

+ + +
+
+ + + + + + + + Add? + Food + Calories + Fat (g) + Saturated Fat (g) + TransFat (g) + Carbs (g) + Fiber (g) + Sugar (g) + Protein (g) + Sodium (mg) + Potassium (mg) + Cholesterol (mg) + + + + + {menuItems.map((menuItem, i) => { + console.log(i); + return( + + + handleCheck(menuItem.item_id)}/> + + {menuItem.item_name} + {menuItem.calories} + {menuItem.fat} + {menuItem.sat_fat} + {menuItem.trans_fat} + {menuItem.carbs} + {menuItem.fiber} + {menuItem.sugar} + {menuItem.protein} + {menuItem.sodium} + {menuItem.potassium} + {menuItem.cholesterol} + + ) + })} + +
+
+
-) - + + ); } -export default MenuExpansion; \ No newline at end of file +export default Menus; \ No newline at end of file diff --git a/db_app/src/components/Menus.js b/db_app/src/components/Menus.js index c4c60ba..800ffaf 100644 --- a/db_app/src/components/Menus.js +++ b/db_app/src/components/Menus.js @@ -37,7 +37,8 @@ const theme = createTheme({ }); function Menus() { - const navigate = useNavigate(); + + const navigate = useNavigate(); const Home = () => { navigate('/Plan'); @@ -108,7 +109,7 @@ const menuExpansion = () => { - + + + + + + + + +
+

+   + Your History +

+ + + +

+     + Past plans by week: +

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

+     + Past actual by week: +

+ + + + + + + + + Week + Calories + Fat (g) + Saturated Fat (g) + TransFat (g) + Carbs (g) + Fiber (g) + Sugar (g) + Protein (g) + Sodium (mg) + Potassium (mg) + Cholesterol (mg) + + + + + {past.map((progress, i) => { + console.log(i); + return( + + + + {progress.week} + + + {progress.calories} + {progress.fat_g} + {progress.sat_fat_g} + {progress.trans_fat_g} + {progress.carbs_g} + {progress.fiber_g} + {progress.sugar_g} + {progress.protein_g} + {progress.sodium_mg} + {progress.potassium_mg} + {progress.cholesterol_mg} + + ) + })} + +
+
+
+
+ + + + + ); + } + + 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 720537b..631415a 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({ @@ -22,11 +22,12 @@ const theme = createTheme({ }, }, - }); +}); function MyPlan() { - const navigate = useNavigate(); + //Navigation functions + const navigate = useNavigate(); const Home = () => { navigate('/Plan'); @@ -36,40 +37,57 @@ function MyPlan() { } const Past = () => { navigate('/Past'); -} -const navigateLogin = () => { + } + const navigateLogin = () => { navigate('/'); -} - -const logout = () => { - ReactSession.set("net_id", ""); - navigateLogin(); - -} -//get the start of each week and reformat to Oracle date type -function weekStart(){ - var date_str = new Date(); - const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] - var weekday = days[date_str.getDay()] - - if (weekday != 'Sunday'){ - return; } - var date_str = new Date(); - var curr_day = String(date_str.getDate()).padStart(2, '0'); - const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']; + const logout = () => { + ReactSession.set("net_id", ""); + navigateLogin(); + } +const Log = () => { + navigate('/LogMeals') +} + +const Progress = () => { + navigate('/ThisWeek') +} + +const [week, setWeek] = useState(); +const displayWeek = () => { + setWeek(() => weekStart()); +} + + +//get start of week (sunday) +function getLastSunday() { + const date = new Date(); + const today = date.getDate(); + const currentDay = date.getDay(); + const newDate = date.setDate(today - (currentDay || 7)); + return new Date(newDate); +} + +//get the Sunday of each week and reformat to Oracle date type +function weekStart(){ + + var date_str = getLastSunday(); + var curr_day = String(date_str.getDate()).padStart(2, '0'); + console.log(curr_day); + const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']; var curr_month = months[date_str.getMonth()]; var curr_year = String(date_str.getFullYear()); var db_date = curr_day + '-' + curr_month + '-' + curr_year.slice(2); - + console.log(db_date) return db_date; } +//Get netid session variable const net_id = ReactSession.get("net_id"); -//to set nutritional goal for the week +//To set nutritional goal for the week const [goalInput, setGoalInput] = useState({ total_cal: 0, total_fat: 0, @@ -85,13 +103,19 @@ const [goalInput, setGoalInput] = useState({ } ); +//Variable to hold the goal input from the form 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 +//Change handler for form submit to send the goal info to the server const changeGoalHandler = evt =>{ setGoalInput({...goalInput, [evt.target.name]: [evt.target.value] }) } +//Variable to hold the success state of submit +const [success, setSuccess] = useState(""); + +//Sends http request to submit goal const submitGoalHandler = evt => { evt.preventDefault(); console.log(goalInput) @@ -116,88 +140,19 @@ const submitGoalHandler = evt => { 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{search_term} = keyword - -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); - }) + setSuccess('Plan saved!'); }; -//to add an off campus food item or meal to your weekly journal - const [offCampusInput, setOffCampusInput] = useState({ - 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 {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 => { - setOffCampusInput({ ...offCampusInput, [evt.target.name]: [evt.target.value] }) - } - - 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); - }) - }; + useEffect(() => { + displayWeek() + console.log('week calculated') + }, []); + + + return ( + - return ( - -
-
+ + + + + + + + + +

  Your Plan

-

   Goal for the week of:

+

   Goal for the week of: {week}

    @@ -348,259 +319,12 @@ const submitSearchHandler = evt => { Submit
+

    {success}



-
-

-     - 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) - - - - - - - - - - - - - - - - - - -
-
-

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

-     - Add to Food Journal -

-

    - On-Campus -

-
-     - - -     - - - -

    - Off-Campus -

-
-     - -

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

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

-

-     - - - -
-
); diff --git a/db_app/src/components/ThisWeek.js b/db_app/src/components/ThisWeek.js new file mode 100644 index 0000000..3a666ee --- /dev/null +++ b/db_app/src/components/ThisWeek.js @@ -0,0 +1,563 @@ +import React,{useState, useEffect} 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 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'; + + +const theme = createTheme({ + palette: { + primary: { + main: lightGreen[700], + apple: red[500], + }, + + }, + }); + +function ThisWeek() { + + const navigate = useNavigate(); + + const Home = () => { + navigate('/Plan'); + } + const Menus = () => { + navigate('/Menus'); + } + const Past = () => { + navigate('/Past'); +} +const navigateLogin = () => { + navigate('/'); +} + +const logout = () => { + ReactSession.set("net_id", ""); + navigateLogin(); + +} + +const Log = () => { + navigate('/LogMeals') + } + + const Progress = () => { + navigate('/ThisWeek') + } +//get the start of each week and reformat to Oracle date type +function weekStart(){ + var date_st = new Date(); + const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] + var weekday = days[date_st.getDay()] + + if (weekday !== 'Sunday'){ + return; + } + + var date_str = new Date(); + var curr_day = String(date_str.getDate()).padStart(2, '0'); + const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']; + + var curr_month = months[date_str.getMonth()]; + var curr_year = String(date_str.getFullYear()); + var db_date = curr_day + '-' + curr_month + '-' + curr_year.slice(2); + + return db_date; +} + +function planDay(){ + var date_s = new Date(); + var index = date_s.getDay(); + return(index + 1) +} + +const net_id = ReactSession.get("net_id"); + + + //Get history of items for this week + 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); + }); + + } + //Get sum of totals for weekly plan (progress) + const [goals, setGoals] = useState([{}]); + const goalURL = (net_id) => `http://3.219.93.142:8000/api/goal/${net_id}`; + + const getGoal = () => { + const net_id = ReactSession.get("net_id"); + const url_to_query = goalURL(net_id); + Axios.get(url_to_query).then((response) => { + console.log(response.data); + setGoals(response.data); + }); + + } + + //Get weekly plan goals + 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); + }); + + } + + const [toDelete, setToDelete] = useState([]); + + const removeItem = (index) => { + setToDelete([ + ...toDelete.slice(0, index), + ...toDelete.slice(index + 1) + ]); + + } + + function handleCheck (i) { + console.log(i); + if (toDelete.indexOf(i) > -1){ + //get index and delete + var index = toDelete.indexOf(i) + removeItem(index); + console.log(`removed ${i}`); + + } + + else{ + setToDelete(toDelete => [...toDelete, i]); + console.log(`added ${i}`); + } + + } + //Delete checked from plan + const sendToPlan = () => { + Axios.delete('http://3.219.93.142:8000/api/week_meals', {net_id: ReactSession.get("net_id"), item_list: toDelete,}).then((response) => { + console.log(response); + }); + } + + + //Set color variables for chips + const [cals, setCals] = useState(false); + const [fat, setFat] = useState(false); + const [trans, setTrans] = useState(false); + const [carbs, setCarbs] = useState(false); + const [sugar, setSugar] = useState(false); + const [fiber, setFiber] = useState(false); + const [cholesterol, setChol] = useState(false); + const [sodium, setSodium] = useState(false); + const [sat, setSat] = useState(false); + const [protein, setProtein] = useState(false); + const [potassium, setPotassium] = useState(false); + + const setColors = () => { + + + + var dayFactor = planDay() / 7; + console.log(dayFactor) + console.log('Sum calories:') + console.log(sum.calories); + console.log('Goals calories:') + console.log(goals.calories); + console.log(goals.calories*dayFactor); + + //set green + if(sum.calories < (1.1*goals.total_cal*dayFactor) && sum.calories >= (0.9*goals.total_cal*dayFactor)){ + setCals(true) + } + else { + setCals(false) + } + if(sum.fat_g < (1.1*goals.total_fat*dayFactor) && sum.fat_g >= (0.9*goals.total_fat*dayFactor)){ + setFat(true) + } + else { + setFat(false) + } + + if(sum.trans_fat_g < (1.1*goals.total_trans_fat*dayFactor) && sum.trans_fat_g >= (0.9*goals.total_trans_fat*dayFactor)){ + setTrans(true) + } + else { + setTrans(false) + } + if(sum.carbs_g < (1.1*goals.total_carbs*dayFactor) && sum.carbs_g >= (0.9*goals.total_carbs*dayFactor)){ + setCarbs(true) + } + else { + setCarbs(false) + } + if(sum.sugar_g < (1.1*goals.total_sugar*dayFactor) && sum.sugar_g >= (0.9*goals.total_sugar*dayFactor)){ + setSugar(true) + } + else { + setSugar(false) + } + if(sum.protein_g < (1.1*goals.total_protein*dayFactor) && sum.protein_g >= (0.9*goals.total_protein*dayFactor)){ + setProtein(true) + } + else { + setProtein(false) + } + if(sum.fiber_g < (1.1*goals.total_fiber*dayFactor) && sum.fiber_g >= (0.9*goals.total_fiber*dayFactor)){ + setFiber(true) + } + else { + setFiber(false) + } + if(sum.cholesterol_mg < (1.1*goals.total_cholesterol*dayFactor) && sum.cholesterol_mg >= (0.9*goals.total_cholesterol*dayFactor)){ + setChol(true) + } + else { + setChol(false) + } + if(sum.sodium_mg < (1.1*goals.total_sodium*dayFactor) && sum.sodium_mg >= (0.9*goals.total_sodium*dayFactor)){ + setSodium(true) + } + else { + setSodium(false) + } + if(sum.sat_fat_g < (1.1*goals.total_sat_fat*dayFactor) && sum.sat_fat_g >= (0.9*goals.total_sat_fat*dayFactor)){ + setSat(true) + } + else { + setSat(false) + } + if(sum.potassium_mg < (1.1*goals.total_potassium*dayFactor) && sum.potassium_mg >= (0.9*goals.total_potassium*dayFactor)){ + setPotassium(true) + } else { + setPotassium(false) + } + + + } + + + + + //Run getSum, getHistory, and getPlan on page load + useEffect(() => { + getHistory() + console.log('History in') + getSum() + console.log('Sum in') + getGoal() + console.log('Goal in') + setColors() + console.log('Colors set') + console.log(planDay()) + }, []); + + + return ( + + + + + + + + + + + + + + + + + + + + + + +
+

+   + So Far This Week: +

+ +

+     + Foods Eaten +

+ + + + + + + + + Remove? + 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( + + + + + + handleCheck(pastitem.item_id)} +/> + + + {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) + + + + + + + + + {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 +

+

    Each category will be red if you are more than 30% off track from your weekly goal for this point in the week.

+

    If it's green, you're pretty much on track!

+ + +             + + +     + +       + +     + +     + +       + +       + +       + +           + +           + + +
+ + +
+ + ); + } + + export default ThisWeek; \ No newline at end of file diff --git a/db_app/src/components/images/back.jpg b/db_app/src/components/images/back.jpg new file mode 100644 index 0000000..05c88f6 Binary files /dev/null and b/db_app/src/components/images/back.jpg differ