From 62392b85975c2dd5de6ba9088e8e7b85983a43b9 Mon Sep 17 00:00:00 2001 From: dbroqua Date: Tue, 18 Sep 2018 22:54:25 +0200 Subject: [PATCH] UX for Vegetable form --- package.json | 1 + src/Vegetable.css | 13 +++ src/Vegetable.js | 255 ++++++++++++++++++++++++++++++---------------- 3 files changed, 180 insertions(+), 89 deletions(-) diff --git a/package.json b/package.json index b7b0f60..2125272 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "dependencies": { "axios": "^0.18.0", "bootstrap": "^4.1.3", + "classnames": "^2.2.6", "react": "^16.5.0", "react-cookie": "^3.0.4", "react-dom": "^16.5.0", diff --git a/src/Vegetable.css b/src/Vegetable.css index 4d2d88a..0f308da 100644 --- a/src/Vegetable.css +++ b/src/Vegetable.css @@ -1,3 +1,8 @@ +.tab-content { + padding: 16px 0; + border-bottom: 1px solid #dee2e6; +} + .map { width: 734px; height: 530px; @@ -16,6 +21,14 @@ top: 33%; font-size: 2rem; } +.nav-item { + cursor: pointer; +} + .imgPreview img { max-width : 100%; } + +#mainPicture { + display: none; +} diff --git a/src/Vegetable.js b/src/Vegetable.js index ce603b7..795b3f4 100644 --- a/src/Vegetable.js +++ b/src/Vegetable.js @@ -1,4 +1,6 @@ -import React, { Component } from 'react'; +import React, { + Component, +} from 'react'; import { Container, Row, @@ -8,8 +10,19 @@ import { Button, Label, Input, + TabContent, + TabPane, + Nav, + NavItem, + NavLink, } from 'reactstrap'; -import { FaEdit, FaMapMarkerAlt } from 'react-icons/fa'; +import classnames from 'classnames'; + +import { + FaPlus, + FaEdit, + FaMapMarkerAlt, +} from 'react-icons/fa'; import Navigation from './Navigation'; import Header from './Header'; import API from './Api'; @@ -30,6 +43,7 @@ class Vegetable extends Component { this.handleChange = this.handleChange.bind(this); this.setMap = this.setMap.bind(this); this.onImageChange = this.onImageChange.bind(this); + this.toggle = this.toggle.bind(this); this.state = { Vegetable: { @@ -43,11 +57,22 @@ class Vegetable extends Component { width: '20px', height: '20px', }, + activeTab: '1' }; this.getVegetable(props.match.params.categoryId, props.match.params.vegetableId); } + toggle(tab) { + if (this.state.activeTab !== tab) { + this.setState({ + activeTab: tab + }, () => { + this.setMap(); + }); + } + } + componentDidMount() { window.addEventListener('resize', this.setMap); this.setMap(); @@ -94,8 +119,6 @@ class Vegetable extends Component { event.stopPropagation(); // Really this time. const fd = new FormData(); - // - // if (this.state.imagePreviewUrl) { fd.append('mainPicture', this.state.Vegetable.mainPictureImported); } @@ -106,7 +129,6 @@ class Vegetable extends Component { } 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 }); @@ -124,7 +146,9 @@ class Vegetable extends Component { if (item.description === null) { item.description = ' '; } - this.setState({ Vegetable: item }); + this.setState({ + Vegetable: item + }); } }) .catch((e) => { @@ -151,7 +175,9 @@ class Vegetable extends Component { } render() { - const { imagePreviewUrl } = this.state; + const { + imagePreviewUrl + } = this.state; let $imagePreview = null; if (imagePreviewUrl) { $imagePreview = (Preview); @@ -167,95 +193,146 @@ class Vegetable extends Component {
- - - - - - + + + + + + + + + + + + + + + + + + + + + + + + this.onImageChange(e)} + /> + + + + +
+ {$imagePreview} +
+ +
-
- - - - +
+ + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ +
- - - - - - - - - - - - - - - - - this.onImageChange(e)} - /> - - -
- {$imagePreview} -
- - - -
-
-
-
-
- -
+ +
+ +