From 23d81786ed9e9f94b8d4291fc32ac582fa11908f Mon Sep 17 00:00:00 2001 From: dbroqua Date: Sat, 16 Mar 2019 22:20:25 +0100 Subject: [PATCH] Fixed bug on search --- src/Components/Map.js | 14 +++++++++++++- src/Components/Vegetables.js | 14 +++++++++++++- src/Routes/Search.js | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Components/Map.js b/src/Components/Map.js index 09ae1c1..2643808 100644 --- a/src/Components/Map.js +++ b/src/Components/Map.js @@ -86,6 +86,18 @@ export default class Map extends React.Component { })); } + createLink(vegetable) { + let url = '/vegetaux/'; + if (vegetable.Type) { + url += `${vegetable.Type.id}-${strToSlug(vegetable.Type.name)}`; + } else { + url += `${this.state.selectedType.id}-${strToSlug(this.state.selectedType.name)}`; + } + url += `/${vegetable.id}-${strToSlug(vegetable.name)}`; + + return url; + } + render() { return ( @@ -97,7 +109,7 @@ export default class Map extends React.Component { && this.state.selectedType.Vegetables && this.state.selectedType.Vegetables.map((vegetable, key) => ( @@ -38,7 +50,7 @@ export default class Map extends React.Component { className={this.state.selectedVegetable.id === vegetable.id ? 'selected' : 'null'} onMouseOver={e => this.props.selectVegetable(vegetable)} > - + {vegetable.name} diff --git a/src/Routes/Search.js b/src/Routes/Search.js index d1316ab..5888d6d 100644 --- a/src/Routes/Search.js +++ b/src/Routes/Search.js @@ -40,6 +40,8 @@ export default class Search extends React.Component { this.setState({ selectedType: { Vegetables: res.data.rows, + id: res.data.rows.length > 0 ? res.data.rows[0].Type.id : null, + name: res.data.rows.length > 0 ? res.data.rows[0].Type.name : null, }, vegetables: res.data.rows, });