cleanup and comments

This commit is contained in:
Ava DeCroix
2023-05-02 17:22:29 -04:00
parent 17f7df6924
commit c2fc10e561
4 changed files with 62 additions and 197 deletions

View File

@@ -27,12 +27,14 @@ const theme = createTheme({
function CreateAccount() { function CreateAccount() {
//Navigate to login
const navigate = useNavigate(); const navigate = useNavigate();
const navigateLogin = () => { const navigateLogin = () => {
navigate('/'); navigate('/');
} }
//State variable for account data
const [data,setData] = useState({ const [data,setData] = useState({
net_id:"", net_id:"",
password:"", password:"",
@@ -40,22 +42,22 @@ function CreateAccount() {
last_name:"", last_name:"",
}) })
//Variable for account data
const {net_id, password, first_name, last_name} = data; const {net_id, password, first_name, last_name} = data;
//Change handler for form
const changeHandler = e => { const changeHandler = e => {
setData({...data,[e.target.name]:[e.target.value]}); setData({...data,[e.target.name]:[e.target.value]});
} }
//Submit handler for form
const submitHandler = e => { const submitHandler = e => {
e.preventDefault(); 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(); createAccount();
navigateLogin();
} }
//Sends post request with account credentials to server
const createAccount = () => { 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) => { 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); console.log(response);

View File

@@ -29,6 +29,8 @@ const theme = createTheme({
export function Login() { export function Login() {
//Navigate functions
const navigate = useNavigate(); const navigate = useNavigate();
const navigateCreateAccount = () => { const navigateCreateAccount = () => {
@@ -39,34 +41,33 @@ export function Login() {
navigate('/Plan'); navigate('/Plan');
} }
//State variable for login data
const [data,setData] = useState({ const [data,setData] = useState({
net_id:"", net_id:"",
password:"" password:""
}) })
//Variable for login data
const {net_id,password} = data; const {net_id,password} = data;
//Change handler for login form
const changeHandler = e => { const changeHandler = e => {
setData({...data,[e.target.name]:[e.target.value]}); setData({...data,[e.target.name]:[e.target.value]});
} }
//Submit handler for login form
const submitHandler = e => { const submitHandler = e => {
e.preventDefault(); e.preventDefault();
login(); login();
} }
//Set session variable for netid
const setSession = () => { const setSession = () => {
ReactSession.set("net_id", net_id[0]); ReactSession.set("net_id", net_id[0]);
} }
//Send http request to log user in
const getHello = () => {
Axios.get("http://3.219.93.142:8000/").then((response) => {
console.log(response.data);
});
};
const login = () => { const login = () => {
Axios.post("http://3.219.93.142:8000/api/auth", {net_id: net_id[0], password: password[0],}).then((response) => { 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);

View File

@@ -35,9 +35,6 @@ import {
} from '@mui/material'; } from '@mui/material';
const theme = createTheme({ const theme = createTheme({
palette: { palette: {
primary: { primary: {
@@ -50,6 +47,7 @@ const theme = createTheme({
function Menus() { function Menus() {
//Navigate function
const navigate = useNavigate(); const navigate = useNavigate();
const Home = () => { const Home = () => {
@@ -64,12 +62,14 @@ function Menus() {
const navigateLogin = () => { const navigateLogin = () => {
navigate('/'); navigate('/');
} }
//Format api all url based on eatery clicked
const makeEateryUrl = (eatery) => `http://3.219.93.142:8000/api/eatery/${eatery}`; const makeEateryUrl = (eatery) => `http://3.219.93.142:8000/api/eatery/${eatery}`;
const getEatery = () => { const getEatery = () => {
return ReactSession.get("eatery"); return ReactSession.get("eatery");
} }
//Http request to get menu items
const getMenu = () => { const getMenu = () => {
const eatery_to_query = getEatery(); const eatery_to_query = getEatery();
Axios.get(makeEateryUrl(eatery_to_query)).then((response) => { 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 [menuItems, setmenuItems] = useState([{}]);
const [toAdd, setToAdd] = 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) => { const removeItem = (index) => {
setToAdd([ setToAdd([
...toAdd.slice(0, index), ...toAdd.slice(0, index),
@@ -103,6 +92,7 @@ const removeItem = (index) => {
} }
//Checkbox handler
function handleCheck (i) { function handleCheck (i) {
console.log(i); console.log(i);
if (toAdd.indexOf(i) > -1){ if (toAdd.indexOf(i) > -1){
@@ -120,12 +110,7 @@ function handleCheck (i) {
} }
//Http request to send checked items to plan
const testChecks = () => {
console.log(toAdd);
}
const sendToPlan = () => { const sendToPlan = () => {
Axios.post('http://3.219.93.142:8000/api/week_meals', {net_id: ReactSession.get("net_id"), item_list: toAdd,}).then((response) => { 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); console.log(response);
@@ -133,6 +118,7 @@ const sendToPlan = () => {
} }
//Run get menu on page load
useEffect(() => { useEffect(() => {
getMenu() getMenu()
console.log('Menu in') console.log('Menu in')
@@ -164,18 +150,8 @@ useEffect(() => {
<AppBar className='bar' position="static"> <AppBar className='bar' position="static">
<Toolbar> <Toolbar>
<h2 sx={{padding:5, margin: 5}}> <h2 sx={{padding:5, margin: 5}}> &nbsp; &nbsp; Menu Items </h2>
&nbsp; &nbsp; <Button sx={{ color: 'white', ':hover': { bgcolor: '#ffc6c4', color: 'white', }, marginLeft: 5 }} onClick={sendToPlan}>Add to Plan</Button>
Menu Items
</h2>
<Button sx={{
color: 'white',
':hover': {
bgcolor: '#ffc6c4',
color: 'white',
},
marginLeft: 5
}} onClick={sendToPlan}>Add to Plan</Button>
</Toolbar> </Toolbar>
</AppBar> </AppBar>
@@ -208,21 +184,11 @@ useEffect(() => {
return( return(
<TableRow <TableRow
key={menuItem.item_name} 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"> <TableCell padding="checkbox">
<Checkbox color="primary" onChange={() => handleCheck(menuItem.item_id)}/>
<Checkbox
color="primary"
onChange={() => handleCheck(menuItem.item_id)}
/>
</TableCell> </TableCell>
<TableCell> <TableCell>{menuItem.item_name}</TableCell>
{menuItem.item_name}
</TableCell>
<TableCell> {menuItem.calories}</TableCell> <TableCell> {menuItem.calories}</TableCell>
<TableCell> {menuItem.fat}</TableCell> <TableCell> {menuItem.fat}</TableCell>
<TableCell> {menuItem.sat_fat}</TableCell> <TableCell> {menuItem.sat_fat}</TableCell>
@@ -242,10 +208,6 @@ useEffect(() => {
</TableContainer> </TableContainer>
</Paper> </Paper>
</ThemeProvider> </ThemeProvider>
); );

View File

@@ -26,6 +26,7 @@ const theme = createTheme({
function MyPlan() { function MyPlan() {
//Navigation functions
const navigate = useNavigate(); const navigate = useNavigate();
const Home = () => { const Home = () => {
@@ -44,7 +45,6 @@ const navigateLogin = () => {
const logout = () => { const logout = () => {
ReactSession.set("net_id", ""); ReactSession.set("net_id", "");
navigateLogin(); navigateLogin();
} }
const Log = () => { const Log = () => {
@@ -70,7 +70,7 @@ function getLastSunday() {
return new Date(newDate); 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(){ function weekStart(){
var date_str = getLastSunday(); var date_str = getLastSunday();
@@ -84,9 +84,10 @@ function weekStart(){
return db_date; return db_date;
} }
//Get netid session variable
const net_id = ReactSession.get("net_id"); 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({ const [goalInput, setGoalInput] = useState({
total_cal: 0, total_cal: 0,
total_fat: 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, 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 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 =>{ const changeGoalHandler = evt =>{
setGoalInput({...goalInput, [evt.target.name]: [evt.target.value] }) setGoalInput({...goalInput, [evt.target.name]: [evt.target.value] })
} }
//Variable to hold the success state of submit
const [success, setSuccess] = useState(""); const [success, setSuccess] = useState("");
//Sends http request to submit goal
const submitGoalHandler = evt => { const submitGoalHandler = evt => {
evt.preventDefault(); evt.preventDefault();
console.log(goalInput) console.log(goalInput)
@@ -138,111 +143,6 @@ const submitGoalHandler = evt => {
setSuccess('Plan saved!'); 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(() => { useEffect(() => {
displayWeek() displayWeek()