cleanup and comments
This commit is contained in:
@@ -27,12 +27,14 @@ const theme = createTheme({
|
||||
|
||||
function CreateAccount() {
|
||||
|
||||
//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);
|
||||
|
||||
@@ -29,6 +29,8 @@ const theme = createTheme({
|
||||
|
||||
|
||||
export function Login() {
|
||||
|
||||
//Navigate functions
|
||||
const navigate = useNavigate();
|
||||
|
||||
const navigateCreateAccount = () => {
|
||||
@@ -39,35 +41,34 @@ export function Login() {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const getHello = () => {
|
||||
Axios.get("http://3.219.93.142:8000/").then((response) => {
|
||||
console.log(response.data);
|
||||
});
|
||||
};
|
||||
|
||||
const login = () => {
|
||||
//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);
|
||||
@@ -77,7 +78,7 @@ const login = () => {
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
|
||||
@@ -35,9 +35,6 @@ import {
|
||||
} from '@mui/material';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const theme = createTheme({
|
||||
palette: {
|
||||
primary: {
|
||||
@@ -50,6 +47,7 @@ const theme = createTheme({
|
||||
|
||||
function Menus() {
|
||||
|
||||
//Navigate function
|
||||
const navigate = useNavigate();
|
||||
|
||||
const Home = () => {
|
||||
@@ -60,16 +58,18 @@ function 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");
|
||||
}
|
||||
|
||||
|
||||
//Http request to get menu items
|
||||
const getMenu = () => {
|
||||
const eatery_to_query = getEatery();
|
||||
Axios.get(makeEateryUrl(eatery_to_query)).then((response) => {
|
||||
@@ -78,23 +78,12 @@ const eatery_to_query = getEatery();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//State variables for menu items and for items to add to plan
|
||||
const [menuItems, setmenuItems] = useState([{}]);
|
||||
const [toAdd, setToAdd] = useState([]);
|
||||
|
||||
const doMenu = () => {
|
||||
const data = getMenu();
|
||||
setmenuItems(data);
|
||||
}
|
||||
|
||||
const buttonTime = () => {
|
||||
getMenu();
|
||||
console.log(menuItems);
|
||||
}
|
||||
|
||||
//Remove an item from the to be added
|
||||
const removeItem = (index) => {
|
||||
setToAdd([
|
||||
...toAdd.slice(0, index),
|
||||
@@ -103,6 +92,7 @@ const removeItem = (index) => {
|
||||
|
||||
}
|
||||
|
||||
//Checkbox handler
|
||||
function handleCheck (i) {
|
||||
console.log(i);
|
||||
if (toAdd.indexOf(i) > -1){
|
||||
@@ -120,12 +110,7 @@ function handleCheck (i) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
const testChecks = () => {
|
||||
console.log(toAdd);
|
||||
}
|
||||
|
||||
//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);
|
||||
@@ -133,6 +118,7 @@ const sendToPlan = () => {
|
||||
|
||||
}
|
||||
|
||||
//Run get menu on page load
|
||||
useEffect(() => {
|
||||
getMenu()
|
||||
console.log('Menu in')
|
||||
@@ -164,18 +150,8 @@ useEffect(() => {
|
||||
|
||||
<AppBar className='bar' position="static">
|
||||
<Toolbar>
|
||||
<h2 sx={{padding:5, margin: 5}}>
|
||||
|
||||
Menu Items
|
||||
</h2>
|
||||
<Button sx={{
|
||||
color: 'white',
|
||||
':hover': {
|
||||
bgcolor: '#ffc6c4',
|
||||
color: 'white',
|
||||
},
|
||||
marginLeft: 5
|
||||
}} onClick={sendToPlan}>Add to Plan</Button>
|
||||
<h2 sx={{padding:5, margin: 5}}> Menu Items </h2>
|
||||
<Button sx={{ color: 'white', ':hover': { bgcolor: '#ffc6c4', color: 'white', }, marginLeft: 5 }} onClick={sendToPlan}>Add to Plan</Button>
|
||||
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
@@ -208,21 +184,11 @@ useEffect(() => {
|
||||
return(
|
||||
<TableRow
|
||||
key={menuItem.item_name}
|
||||
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
|
||||
>
|
||||
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}>
|
||||
<TableCell padding="checkbox">
|
||||
|
||||
|
||||
<Checkbox
|
||||
|
||||
color="primary"
|
||||
onChange={() => handleCheck(menuItem.item_id)}
|
||||
/>
|
||||
<Checkbox color="primary" onChange={() => handleCheck(menuItem.item_id)}/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{menuItem.item_name}
|
||||
</TableCell>
|
||||
|
||||
<TableCell>{menuItem.item_name}</TableCell>
|
||||
<TableCell> {menuItem.calories}</TableCell>
|
||||
<TableCell> {menuItem.fat}</TableCell>
|
||||
<TableCell> {menuItem.sat_fat}</TableCell>
|
||||
@@ -242,10 +208,6 @@ useEffect(() => {
|
||||
</TableContainer>
|
||||
</Paper>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ThemeProvider>
|
||||
|
||||
);
|
||||
|
||||
@@ -22,10 +22,11 @@ const theme = createTheme({
|
||||
},
|
||||
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
function MyPlan() {
|
||||
|
||||
//Navigation functions
|
||||
const navigate = useNavigate();
|
||||
|
||||
const Home = () => {
|
||||
@@ -36,16 +37,15 @@ function MyPlan() {
|
||||
}
|
||||
const Past = () => {
|
||||
navigate('/Past');
|
||||
}
|
||||
const navigateLogin = () => {
|
||||
}
|
||||
const navigateLogin = () => {
|
||||
navigate('/');
|
||||
}
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
const logout = () => {
|
||||
ReactSession.set("net_id", "");
|
||||
navigateLogin();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const Log = () => {
|
||||
navigate('/LogMeals')
|
||||
@@ -70,7 +70,7 @@ function getLastSunday() {
|
||||
return new Date(newDate);
|
||||
}
|
||||
|
||||
//get the start of each week and reformat to Oracle date type
|
||||
//get the Sunday of each week and reformat to Oracle date type
|
||||
function weekStart(){
|
||||
|
||||
var date_str = getLastSunday();
|
||||
@@ -84,9 +84,10 @@ function weekStart(){
|
||||
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,
|
||||
@@ -102,15 +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)
|
||||
@@ -138,111 +143,6 @@ const submitGoalHandler = evt => {
|
||||
setSuccess('Plan saved!');
|
||||
};
|
||||
|
||||
//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({
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user