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, });