From 04ef7f4498fefe294b33169744643d7da001a5a3 Mon Sep 17 00:00:00 2001 From: dbroqua Date: Wed, 21 Nov 2018 08:16:11 +0100 Subject: [PATCH] First template for vegetable page --- src/Components/App.js | 2 + src/Routes/Vegetable.js | 170 ++++++++++++++++++++++++++++++++++++++++ src/css/index.css | 13 +++ 3 files changed, 185 insertions(+) create mode 100644 src/Routes/Vegetable.js diff --git a/src/Components/App.js b/src/Components/App.js index ec40e81..684367b 100644 --- a/src/Components/App.js +++ b/src/Components/App.js @@ -7,6 +7,7 @@ import { import Map from '../Routes/Map'; import Home from '../Routes/Home'; import Vegetables from '../Routes/Vegetables'; +import Vegetable from '../Routes/Vegetable'; class App extends Component { constructor(props) { @@ -44,6 +45,7 @@ class App extends Component { + diff --git a/src/Routes/Vegetable.js b/src/Routes/Vegetable.js new file mode 100644 index 0000000..d2354f1 --- /dev/null +++ b/src/Routes/Vegetable.js @@ -0,0 +1,170 @@ +import React from 'react'; +import { + Container, + Row, + Col, + ListGroup, + ListGroupItem, + Carousel, + CarouselItem, + CarouselControl, + CarouselIndicators, + CarouselCaption +} from 'reactstrap'; +import { + NotificationContainer, + NotificationManager, +} from 'react-notifications'; +import Api from '../Components/Api'; +import MapItem from '../Components/Map'; + +export default class RouterVegetable extends React.Component { + constructor(props) { + super(props); + + this.state = { + typeId: props.match.params.typeId, + vegetableId: props.match.params.vegetableId, + selectedType: { + name: '', + Vegetables: [] + }, + item: {}, + activeIndex: 0 + }; + + this.getItem = this.getItem.bind(this); + this.next = this.next.bind(this); + this.previous = this.previous.bind(this); + this.goToIndex = this.goToIndex.bind(this); + this.onExiting = this.onExiting.bind(this); + this.onExited = this.onExited.bind(this); + + this.getItem(); + } + + onExiting() { + this.animating = true; + } + + onExited() { + this.animating = false; + } + + next() { + if (this.animating) return; + const nextIndex = this.state.activeIndex === this.state.item.Pictures.length - 1 ? 0 : this.state.activeIndex + 1; + this.setState({ activeIndex: nextIndex }); + } + + previous() { + if (this.animating) return; + const nextIndex = this.state.activeIndex === 0 ? this.state.item.Pictures.length - 1 : this.state.activeIndex - 1; + this.setState({ activeIndex: nextIndex }); + } + + goToIndex(newIndex) { + if (this.animating) return; + this.setState({ activeIndex: newIndex }); + } + + getItem() { + Api.get(`/types/${this.state.typeId}/vegetables/${this.state.vegetableId}`) + .then((res) => { + this.setState({ + selectedType: { + id: res.data.Type.id, + name: res.data.Type.name, + Vegetables: [ + res.data + ] + }, + item: res.data, + }); + }) + .catch(() => { + NotificationManager.error('Erreur lors de la récupération du végétal'); + }); + } + + render() { + const { activeIndex } = this.state; + + return ( + + + + + + +

» {this.state.item.name}

+ +
+ + + { }} + /> + + + + + + {this.state.item && + this.state.item.Properties && + this.state.item.Properties.map((item, key) => { + return ( + item.Property !== null && + item.Property !== undefined ? + ( + + {item.Property.name} : {item.value} + + ) + : + (null) + ) + })} + + + + + + + + {this.state.item && + this.state.item.Pictures ? + ( + + + {this.state.item && + this.state.item.Pictures && + this.state.item.Pictures.map((picture) => ( + + {picture.url} + + ))} + + + + ) : (null) + } + + + + +
+
+ ); + } +} diff --git a/src/css/index.css b/src/css/index.css index 55121de..1956de3 100644 --- a/src/css/index.css +++ b/src/css/index.css @@ -35,4 +35,17 @@ body { .container { margin-top: 116px; +} + + +.double { + display: inherit; + columns: 2; + -webkit-columns: 2; + -moz-columns: 2; +} +.double li { + /* width:50%; + float:left; + display:inline; */ } \ No newline at end of file