Browse Source

meal image upload working. had to force update for whatever reason

Ramona Plogmann 4 years ago
parent
commit
1017f1fad2
51 changed files with 225 additions and 0 deletions
  1. 6 0
      .idea/jsLibraryMappings.xml
  2. 219 0
      client/src/components/Meals/EditMeal.jsx
  3. BIN
      server/uploads/mealImages/1610801752246-IMG_5286.JPG
  4. BIN
      server/uploads/mealImages/1610802855539-IMG_5286.JPG
  5. BIN
      server/uploads/mealImages/1610806949494-IMG_5304.JPG
  6. BIN
      server/uploads/mealImages/1610806996589-Bahn.JPG
  7. BIN
      server/uploads/mealImages/1610807075847-Fotos für hanna (46).JPG
  8. BIN
      server/uploads/mealImages/1610807227463-Zahnspange raus ;).jpg
  9. BIN
      server/uploads/mealImages/1610808309633-IMG_1084.JPG
  10. BIN
      server/uploads/mealImages/1610808309674-IMG_1087.JPG
  11. BIN
      server/uploads/mealImages/1610808309685-IMG_1089.JPG
  12. BIN
      server/uploads/mealImages/1610808309703-IMG_2934.JPG
  13. BIN
      server/uploads/mealImages/1610808309736-IMG_1167.JPG
  14. BIN
      server/uploads/mealImages/1610808309756-IMG_3303.JPG
  15. BIN
      server/uploads/mealImages/1610808409181-IMG_3733.JPG
  16. BIN
      server/uploads/mealImages/1610808409197-IMG_4786.JPG
  17. BIN
      server/uploads/mealImages/1610808409208-IMG_5071.JPG
  18. BIN
      server/uploads/mealImages/1610808409222-IMG_5191.JPG
  19. BIN
      server/uploads/mealImages/1610808409230-IMG_5286.JPG
  20. BIN
      server/uploads/mealImages/1610808549931-IMG_5484.JPG
  21. BIN
      server/uploads/mealImages/1610808549950-IMG_5485.JPG
  22. BIN
      server/uploads/mealImages/1610808549971-IMG_5486.JPG
  23. BIN
      server/uploads/mealImages/1610808549983-IMG_5886.JPG
  24. BIN
      server/uploads/mealImages/1610808549993-IMG_5887.JPG
  25. BIN
      server/uploads/mealImages/1610808756348-IMG_0715.JPG
  26. BIN
      server/uploads/mealImages/1610808756373-IMG_0730.JPG
  27. BIN
      server/uploads/mealImages/1610808756390-IMG_0725.JPG
  28. BIN
      server/uploads/mealImages/1610808827050-Emealay_Logo_weiss.png
  29. BIN
      server/uploads/mealImages/1610809419380-IMG_0925.JPG
  30. BIN
      server/uploads/mealImages/1610809419400-IMG_0929.JPG
  31. BIN
      server/uploads/mealImages/1610809419426-IMG_0928.JPG
  32. BIN
      server/uploads/mealImages/1610809493306-IMG_0715.JPG
  33. BIN
      server/uploads/mealImages/1610809493339-IMG_0730.JPG
  34. BIN
      server/uploads/mealImages/1610809493359-IMG_0725.JPG
  35. BIN
      server/uploads/mealImages/1610809500835-IMG_0730.JPG
  36. BIN
      server/uploads/mealImages/1610809524191-IMG_0855.JPG
  37. BIN
      server/uploads/mealImages/1610809670831-IMG_0925.JPG
  38. BIN
      server/uploads/mealImages/1610809678835-IMG_0852.JPG
  39. BIN
      server/uploads/mealImages/1610809683250-IMG_0833.JPG
  40. BIN
      server/uploads/mealImages/1610809695236-IMG_0928.JPG
  41. BIN
      server/uploads/mealImages/1610810839018-IMG_0915.JPG
  42. BIN
      server/uploads/mealImages/1610810839061-IMG_0921.JPG
  43. BIN
      server/uploads/mealImages/1610810839083-IMG_0925.JPG
  44. BIN
      server/uploads/mealImages/1610810839109-IMG_0928.JPG
  45. BIN
      server/uploads/mealImages/1610810839119-IMG_0929.JPG
  46. BIN
      server/uploads/mealImages/1610811811017-IMG_0925.JPG
  47. BIN
      server/uploads/mealImages/1610811814770-IMG_0928.JPG
  48. BIN
      server/uploads/mealImages/1610811967033-IMG_0925.JPG
  49. BIN
      server/uploads/mealImages/1610811967043-IMG_0928.JPG
  50. BIN
      server/uploads/mealImages/1610812064235-IMG_0852.JPG
  51. BIN
      server/uploads/mealImages/1610812064460-IMG_0855.JPG

+ 6 - 0
.idea/jsLibraryMappings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="JavaScriptLibraryMappings">
+    <includedPredefinedLibrary name="Node.js Core" />
+  </component>
+</project>

+ 219 - 0
client/src/components/Meals/EditMeal.jsx

@@ -0,0 +1,219 @@
+import React, { useEffect, useState } from 'react';
+import { Button, Checkbox, Dialog, DialogActions, DialogContent, DialogTitle, FormControlLabel, TextField, IconButton, Snackbar } from '@material-ui/core';
+// import MuiAlert from '@material-ui/lab/Alert';
+import DeleteIcon from '@material-ui/icons/Delete';
+import { makeStyles } from '@material-ui/styles';
+import axios from 'axios';
+import { func, bool, string } from "prop-types";
+import dateformat from 'dateformat';
+
+const useStyles = makeStyles((theme) => ({
+  dateSelectionWrapper: {
+    display: 'flex',
+    justifyContent: 'space-between',
+  },
+  dateLabel: {
+    marginTop: 'calc(10px + 1em)',
+    marginBottom: 'calc(10px + 1em)',
+  },
+  dateSelection: {
+    marginTop: '1em',
+    marginBottom: '1em',
+    marginLeft: 'auto',
+  },
+  form: {
+    padding: '0.5em',
+  },
+  textField: {
+    width: '100%',
+    marginTop: '1em',
+    marginBottom: '1em',
+  },
+  submitButton: {
+    margin: '1.5em 0 0',
+  },
+  actionButtonWrapper: {
+    justifyContent: "space-around",
+  },
+  actionButtons: {
+    marginLeft: 0,
+  },
+  actionButtonDelete: {
+    marginLeft: 0,
+    color: theme.palette.error.main,
+  },
+  snackbarOffset: {
+    bottom: '58px', // todo make adapt to bottomNavHeight
+  },
+  deleteSnackbar: {
+    backgroundColor: theme.palette.error.light,
+  },
+  readdSnackbar: {
+    backgroundColor: theme.palette.primary.light,
+  },
+}));
+
+const EditPlanItem = (props) => {
+  const classes = useStyles();
+
+  const { closeDialog, onDoneEditing, planItem, open } = props;
+
+  const [title, setTitle] = useState('');
+  const [date, setDate] = useState(new Date());
+  const [useDate, setUseDate] = useState(false);
+  const [gotEverything, setGotEverything] = useState(true);
+
+  const [deleteMessageVisible, setDeleteMessageVisible] = useState(false);
+  const [readdedMessageVisible, setReaddedMessageVisible] = useState(false);
+  const [deletedItem, setDeletedItem] = useState(null);
+
+  useEffect(() => {
+    console.log('in edit', planItem);
+    if (planItem) {
+      setTitle(planItem.title);
+      setUseDate(planItem.hasDate);
+      setDate(planItem.date ? new Date(planItem.date) : new Date());
+      setGotEverything(planItem.gotEverything);
+    }
+  }, [planItem])
+
+  const resetInputs = () => {
+    setTitle('');
+    setDate(null);
+    setUseDate(false);
+    setGotEverything(true);
+  }
+
+  const editPlan = () => {
+    console.log('trying to edit', title);
+    if (title) {
+      const newPlan = {
+        title,
+        date: useDate ? new Date(date) : null,
+        gotEverything,
+        tags: [],
+        hasDate: useDate,
+      }
+      console.log(newPlan);
+
+      axios.post('http://localhost:5000/plans/edit/' + planItem._id, newPlan).then((result) => {
+        console.log('edit request sent', result.data);
+        onDoneEditing();
+      });
+
+      resetInputs();
+    }
+  }
+
+  const deletePlan = () => {
+
+    axios.post('http://localhost:5000/plans/delete/' + planItem._id).then((result) => {
+      setDeletedItem(planItem);
+      setDeleteMessageVisible(true);
+      console.log('delete request sent', result.data);
+      resetInputs();
+      onDoneEditing();
+      closeDialog();
+    });
+  }
+
+  const undoDeletion = () => {
+    axios.post('http://localhost:5000/plans/add', deletedItem).then((result) => {
+      console.log('re-add request sent', result.data);
+      setDeleteMessageVisible(false);
+      setReaddedMessageVisible(true);
+      onDoneEditing();
+    });
+  }
+
+  return (
+    <>
+      <Dialog open={open && planItem} onClose={closeDialog} aria-labelledby="form-dialog-title" onKeyDown={e => {
+        if (e.keyCode === 13) {
+          // validateForm();
+          closeDialog();
+        }
+      }}>
+        <DialogTitle id="form-dialog-title">Edit Plan</DialogTitle>
+        <DialogContent>
+          <form noValidate className={classes.form}>
+            <TextField className={classes.textField} value={title} onChange={e => setTitle(e.target.value)} label="Title" variant="outlined" autoFocus />
+            <br />
+            <div className={classes.dateSelectionWrapper}>
+              <FormControlLabel className={classes.dateLabel} label="Date" control={
+                <Checkbox checked={useDate} onChange={e => setUseDate(e.target.checked)} color="primary" />
+              } />
+              {useDate ?
+                <TextField className={classes.dateSelection}
+                           value={dateformat(date, 'yyyy-mm-dd')}
+                           onChange={e => setDate(e.target.value)}
+                           label="Due Date"
+                           type="date"
+                           variant="outlined"
+                           InputLabelProps={{ shrink: true, }} />
+                : ''}
+            </div>
+            <FormControlLabel label="Got everything?" control={
+              <Checkbox checked={gotEverything} onChange={e => setGotEverything(e.target.checked)} color="primary" />
+            } />
+          </form>
+          <DialogActions className={classes.actionButtonWrapper}>
+            <Button className={classes.actionButtons} color="primary" onClick={closeDialog}>Cancel</Button>
+            {/*<Button color="secondary" onClick={() => {}} variant="outlined">Delete</Button>*/}
+            <IconButton className={classes.actionButtonDelete} onClick={deletePlan} aria-label="delete">
+              <DeleteIcon />
+            </IconButton>
+            <Button className={classes.actionButtons} color="primary" variant="contained" onClick={() => {
+              editPlan();
+              closeDialog();
+            }}>Save</Button>
+          </DialogActions>
+        </DialogContent>
+      </Dialog>
+
+
+      <Snackbar open={deleteMessageVisible}
+                autoHideDuration={3000}
+                onClose={() => {setDeleteMessageVisible(false); }}
+                message={`Plan ${deletedItem ? deletedItem.title + ' ' : ''}deleted!`}
+                action={
+                  <Button color="inherit" size="small" onClick={undoDeletion}>
+                    Undo
+                  </Button>
+                }
+                className={classes.snackbarOffset}
+                ContentProps={{ className: classes.deleteSnackbar }} />
+
+      <Snackbar open={readdedMessageVisible}
+                autoHideDuration={1000}
+                onClose={() => {setReaddedMessageVisible(false); }}
+                message={`Plan ${deletedItem ? '"' + deletedItem.title + '" ' : ''}re-added!`}
+                className={classes.snackbarOffset}
+                ContentProps={{ className: classes.readdSnackbar }} />
+    </>
+  );
+}
+
+EditPlanItem.propTypes = {
+  planItem: {
+    title: string,
+    gotEverything: bool,
+    hasDate: bool,
+    date: string,
+  },
+  open: bool.isRequired,
+  onDoneEditing: func.isRequired,
+  closeDialog: func.isRequired,
+}
+
+EditPlanItem.defaultProps = {
+  planItem: {
+    title: '',
+    gotEverything: false,
+    hasDate: false,
+    date: null,
+  },
+}
+
+export default EditPlanItem;
+

BIN
server/uploads/mealImages/1610801752246-IMG_5286.JPG


BIN
server/uploads/mealImages/1610802855539-IMG_5286.JPG


BIN
server/uploads/mealImages/1610806949494-IMG_5304.JPG


BIN
server/uploads/mealImages/1610806996589-Bahn.JPG


BIN
server/uploads/mealImages/1610807075847-Fotos für hanna (46).JPG


BIN
server/uploads/mealImages/1610807227463-Zahnspange raus ;).jpg


BIN
server/uploads/mealImages/1610808309633-IMG_1084.JPG


BIN
server/uploads/mealImages/1610808309674-IMG_1087.JPG


BIN
server/uploads/mealImages/1610808309685-IMG_1089.JPG


BIN
server/uploads/mealImages/1610808309703-IMG_2934.JPG


BIN
server/uploads/mealImages/1610808309736-IMG_1167.JPG


BIN
server/uploads/mealImages/1610808309756-IMG_3303.JPG


BIN
server/uploads/mealImages/1610808409181-IMG_3733.JPG


BIN
server/uploads/mealImages/1610808409197-IMG_4786.JPG


BIN
server/uploads/mealImages/1610808409208-IMG_5071.JPG


BIN
server/uploads/mealImages/1610808409222-IMG_5191.JPG


BIN
server/uploads/mealImages/1610808409230-IMG_5286.JPG


BIN
server/uploads/mealImages/1610808549931-IMG_5484.JPG


BIN
server/uploads/mealImages/1610808549950-IMG_5485.JPG


BIN
server/uploads/mealImages/1610808549971-IMG_5486.JPG


BIN
server/uploads/mealImages/1610808549983-IMG_5886.JPG


BIN
server/uploads/mealImages/1610808549993-IMG_5887.JPG


BIN
server/uploads/mealImages/1610808756348-IMG_0715.JPG


BIN
server/uploads/mealImages/1610808756373-IMG_0730.JPG


BIN
server/uploads/mealImages/1610808756390-IMG_0725.JPG


BIN
server/uploads/mealImages/1610808827050-Emealay_Logo_weiss.png


BIN
server/uploads/mealImages/1610809419380-IMG_0925.JPG


BIN
server/uploads/mealImages/1610809419400-IMG_0929.JPG


BIN
server/uploads/mealImages/1610809419426-IMG_0928.JPG


BIN
server/uploads/mealImages/1610809493306-IMG_0715.JPG


BIN
server/uploads/mealImages/1610809493339-IMG_0730.JPG


BIN
server/uploads/mealImages/1610809493359-IMG_0725.JPG


BIN
server/uploads/mealImages/1610809500835-IMG_0730.JPG


BIN
server/uploads/mealImages/1610809524191-IMG_0855.JPG


BIN
server/uploads/mealImages/1610809670831-IMG_0925.JPG


BIN
server/uploads/mealImages/1610809678835-IMG_0852.JPG


BIN
server/uploads/mealImages/1610809683250-IMG_0833.JPG


BIN
server/uploads/mealImages/1610809695236-IMG_0928.JPG


BIN
server/uploads/mealImages/1610810839018-IMG_0915.JPG


BIN
server/uploads/mealImages/1610810839061-IMG_0921.JPG


BIN
server/uploads/mealImages/1610810839083-IMG_0925.JPG


BIN
server/uploads/mealImages/1610810839109-IMG_0928.JPG


BIN
server/uploads/mealImages/1610810839119-IMG_0929.JPG


BIN
server/uploads/mealImages/1610811811017-IMG_0925.JPG


BIN
server/uploads/mealImages/1610811814770-IMG_0928.JPG


BIN
server/uploads/mealImages/1610811967033-IMG_0925.JPG


BIN
server/uploads/mealImages/1610811967043-IMG_0928.JPG


BIN
server/uploads/mealImages/1610812064235-IMG_0852.JPG


BIN
server/uploads/mealImages/1610812064460-IMG_0855.JPG