diff --git a/public/plan.jpg b/public/plan.jpg
new file mode 100644
index 0000000..5094720
Binary files /dev/null and b/public/plan.jpg differ
diff --git a/src/App.css b/src/App.css
index 2aef9b3..816adea 100644
--- a/src/App.css
+++ b/src/App.css
@@ -26,6 +26,11 @@
margin: 0;
}
+.Vegetable input {
+ margin: 0;
+ min-width: auto;
+}
+
.container {
border-radius: 12px;
background: #fafafa;
diff --git a/src/App.js b/src/App.js
index 6afd387..c612e08 100644
--- a/src/App.js
+++ b/src/App.js
@@ -5,6 +5,7 @@ import {
} from 'react-router-dom';
import Categories from './Categories';
import Category from './Category';
+import Vegetable from './Vegetable';
import requireAuth from './requireAuth';
import Login from './Login';
@@ -20,10 +21,7 @@ class App extends Component {
- {/*
-
-
- */}
+
diff --git a/src/Categories.js b/src/Categories.js
index 4a34a65..bb81511 100644
--- a/src/Categories.js
+++ b/src/Categories.js
@@ -7,7 +7,7 @@ import {
Button,
Input,
} from 'reactstrap';
-import { FaTrashAlt } from 'react-icons/fa';
+import { FaTrashAlt, FaPlus } from 'react-icons/fa';
import { Link } from 'react-router-dom';
import Header from './Header';
import API from './Api';
@@ -104,24 +104,24 @@ class Categories extends Component {
))}
-
-
-
- |
-
+
);
}
diff --git a/src/Category.js b/src/Category.js
index 2a3e00a..9772d60 100644
--- a/src/Category.js
+++ b/src/Category.js
@@ -7,7 +7,7 @@ import {
Button,
Input,
} from 'reactstrap';
-import { FaTrashAlt } from 'react-icons/fa';
+import { FaTrashAlt, FaPlus, FaEdit } from 'react-icons/fa';
import { Link } from 'react-router-dom';
import Header from './Header';
import API from './Api';
@@ -80,6 +80,9 @@ class Category extends Component {
event.stopPropagation(); // Really this time.
API.post(`types/${this.state.Category.id}/vegetables/`, {
name: this.state.name,
+ lat: 0,
+ lng: 0,
+ description: '',
})
.then((res) => {
const Category = this.state.Category;
@@ -120,7 +123,11 @@ class Category extends Component {
onChange={this.handleChange}
/>
-
+
@@ -141,23 +148,23 @@ class Category extends Component {
))}
-
-
-
- |
-
+
);
}
diff --git a/src/Login.js b/src/Login.js
index cc9c248..567b63f 100644
--- a/src/Login.js
+++ b/src/Login.js
@@ -9,6 +9,7 @@ import {
Input,
Alert,
} from 'reactstrap';
+import { FaSignInAlt } from 'react-icons/fa';
import API, { setDefaults } from './Api';
class Login extends Component {
@@ -101,7 +102,11 @@ class Login extends Component {
{this.state.message}
) : (null)}
-
+
diff --git a/src/Vegetable.css b/src/Vegetable.css
new file mode 100644
index 0000000..4d2d88a
--- /dev/null
+++ b/src/Vegetable.css
@@ -0,0 +1,21 @@
+.map {
+ width: 734px;
+ height: 530px;
+ background: url('/plan.jpg');
+ background-size: cover;
+ position: relative;
+}
+.mapMarker {
+position: absolute;
+left: 25%;
+top: 33%;
+}
+
+.mapMarker svg {
+ color: red;
+ font-size: 2rem;
+}
+
+.imgPreview img {
+ max-width : 100%;
+}
diff --git a/src/Vegetable.js b/src/Vegetable.js
new file mode 100644
index 0000000..0562a00
--- /dev/null
+++ b/src/Vegetable.js
@@ -0,0 +1,262 @@
+import React, { Component } from 'react';
+import {
+ Container,
+ Row,
+ Col,
+ Form,
+ FormGroup,
+ Button,
+ Label,
+ Input,
+} from 'reactstrap';
+import { FaEdit, FaMapMarkerAlt } from 'react-icons/fa';
+import Header from './Header';
+import API from './Api';
+
+import './Vegetable.css';
+
+const Map = {
+ width: 734,
+ height: 530,
+};
+
+class Vegetable extends Component {
+ constructor(props) {
+ super(props);
+
+ this.getVegetable = this.getVegetable.bind(this);
+ this.updateVegetable = this.updateVegetable.bind(this);
+ this.handleChange = this.handleChange.bind(this);
+ this.setMap = this.setMap.bind(this);
+ this.onImageChange = this.onImageChange.bind(this);
+
+ this.state = {
+ Vegetable: {
+ name: '',
+ lat: 0,
+ lng: 0,
+ description: '',
+ },
+ imagePreviewUrl: '',
+ Map: {
+ width: '20px',
+ height: '20px',
+ },
+ };
+
+ this.getVegetable(props.match.params.categoryId, props.match.params.vegetableId);
+ }
+
+ componentDidMount() {
+ window.addEventListener('resize', this.setMap);
+ this.setMap();
+ }
+
+ componentWillUnmount() {
+ window.removeEventListener('resize', this.setMap);
+ }
+
+ handleChange(event) {
+ const target = event.target;
+ const value = target.type === 'checkbox' ? target.checked : target.value;
+ const name = target.name;
+
+ this.setState(prevState => ({
+ Vegetable: {
+ ...prevState.Vegetable,
+ [name]: value,
+ },
+ }));
+ }
+
+ onImageChange(e) {
+ e.preventDefault();
+
+ const reader = new FileReader();
+ const file = e.target.files[0];
+
+ reader.onloadend = () => {
+ this.setState(prevState => ({
+ Vegetable: {
+ ...prevState.Vegetable,
+ mainPictureImported: file,
+ },
+ imagePreviewUrl: reader.result,
+ }));
+ };
+
+ reader.readAsDataURL(file);
+ }
+
+ updateVegetable(event) {
+ event.preventDefault(); // Let's stop this event.
+ event.stopPropagation(); // Really this time.
+
+ const fd = new FormData();
+ //
+ //
+ if (this.state.imagePreviewUrl) {
+ fd.append('mainPicture', this.state.Vegetable.mainPictureImported);
+ }
+
+ Object.keys(this.state.Vegetable).map((objectKey) => {
+ if (objectKey !== 'mainPicture' && objectKey !== 'mainPictureImported') {
+ fd.append(objectKey, this.state.Vegetable[objectKey]);
+ }
+ return true;
+ });
+ console.log(this.state.Vegetable);
+ API.patch(`types/${this.state.Vegetable.Type.id}/vegetables/${this.state.Vegetable.id}`, fd)
+ .then((res) => {
+ // this.setState({ Category: res.data });
+ })
+ .catch(() => {
+ alert('Impossile de mettre à jour cette catégorie');
+ });
+ }
+
+ getVegetable(categoryId, vegetableId) {
+ API.get(`types/${categoryId}/vegetables/${vegetableId}`)
+ .then((res) => {
+ if (res.status === 200) {
+ const item = res.data;
+ if (item.description === null) {
+ item.description = ' ';
+ }
+ this.setState({ Vegetable: item });
+ }
+ })
+ .catch((e) => {
+ alert('Erreur lors de la récupération de ce végétal');
+ });
+ }
+
+ setMap() {
+ const width = document.getElementById('MapContainer').clientWidth;
+ let MapWidth = Map.width;
+ let MapHeight = Map.height;
+
+ if (width < Map.width) {
+ MapWidth = width;
+ MapHeight = Math.round(Map.height * MapWidth / Map.width);
+ }
+
+ this.setState({
+ Map: {
+ width: MapWidth,
+ height: MapHeight,
+ },
+ });
+ }
+
+ render() {
+ const { imagePreviewUrl } = this.state;
+ let $imagePreview = null;
+ if (imagePreviewUrl) {
+ $imagePreview = (
);
+ } else if (this.state.Vegetable.mainPicture) {
+ $imagePreview = (
);
+ } else {
+ $imagePreview = ();
+ }
+
+ return (
+
+
+
+
+ );
+ }
+}
+
+export default Vegetable;