latest round of updates

This commit is contained in:
Ava DeCroix
2023-05-01 23:01:32 -04:00
parent 370866232a
commit 17f7df6924
2 changed files with 57 additions and 3 deletions

View File

@@ -109,6 +109,8 @@ const changeGoalHandler = evt =>{
setGoalInput({...goalInput, [evt.target.name]: [evt.target.value] }) setGoalInput({...goalInput, [evt.target.name]: [evt.target.value] })
} }
const [success, setSuccess] = useState("");
const submitGoalHandler = evt => { const submitGoalHandler = evt => {
evt.preventDefault(); evt.preventDefault();
console.log(goalInput) console.log(goalInput)
@@ -133,6 +135,7 @@ const submitGoalHandler = evt => {
console.log(response); console.log(response);
console.log(response.status); console.log(response.status);
}) })
setSuccess('Plan saved!');
}; };
//to find a food item from an on campus location to your weekly journal //to find a food item from an on campus location to your weekly journal
@@ -416,6 +419,7 @@ const submitSearchHandler = evt => {
Submit</Button> Submit</Button>
</form> </form>
</div> </div>
<h2> &nbsp; &nbsp; {success}</h2>
<br></br> <br></br>

View File

@@ -142,6 +142,39 @@ const net_id = ReactSession.get("net_id");
} }
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 //Set color variables for chips
const [cals, setCals] = useState(false); const [cals, setCals] = useState(false);
@@ -242,7 +275,6 @@ const net_id = ReactSession.get("net_id");
//Run getSum, getHistory, and getPlan on page load //Run getSum, getHistory, and getPlan on page load
useEffect(() => { useEffect(() => {
getHistory() getHistory()
@@ -309,6 +341,14 @@ const net_id = ReactSession.get("net_id");
&nbsp; &nbsp; &nbsp; &nbsp;
Foods Eaten Foods Eaten
</h3> </h3>
<Button sx={{
color: 'main',
':hover': {
bgcolor: 'green',
color: 'white',
},
marginLeft: 5
}} onClick={sendToPlan}> Remove checked from log</Button>
<Paper sx={{ width: '100%', overflow: 'hidden' }}> <Paper sx={{ width: '100%', overflow: 'hidden' }}>
<TableContainer component={Paper} sx={{margin: 5, maxHeight: 200, maxWidth:1400}}> <TableContainer component={Paper} sx={{margin: 5, maxHeight: 200, maxWidth:1400}}>
@@ -316,7 +356,7 @@ const net_id = ReactSession.get("net_id");
<TableHead> <TableHead>
<TableRow sx={{maxWidth:1400}}> <TableRow sx={{maxWidth:1400}}>
<TableCell style={{ maxWidth: 110}} align="left">Remove?</TableCell>
<TableCell style={{ maxWidth: 110}} align="left">Food</TableCell> <TableCell style={{ maxWidth: 110}} align="left">Food</TableCell>
<TableCell style={{ maxWidth: 90 }} align="left">Calories</TableCell> <TableCell style={{ maxWidth: 90 }} align="left">Calories</TableCell>
<TableCell style={{ maxWidth: 70 }} align="left">Fat&nbsp;(g)</TableCell> <TableCell style={{ maxWidth: 70 }} align="left">Fat&nbsp;(g)</TableCell>
@@ -341,10 +381,20 @@ const net_id = ReactSession.get("net_id");
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(pastitem.item_id)}
/>
</TableCell>
<TableCell> <TableCell>
{pastitem.item_name} {pastitem.item_name}
</TableCell> </TableCell>
<TableCell> {pastitem.calories}</TableCell> <TableCell> {pastitem.calories}</TableCell>
<TableCell> {pastitem.fat_g}</TableCell> <TableCell> {pastitem.fat_g}</TableCell>
<TableCell> {pastitem.sat_fat_g}</TableCell> <TableCell> {pastitem.sat_fat_g}</TableCell>