Fixed bug on search

This commit is contained in:
dbroqua 2019-03-16 22:20:25 +01:00
parent 51fa7f013f
commit 23d81786ed
3 changed files with 28 additions and 2 deletions

View File

@ -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 (
<Row className="with-margin">
@ -97,7 +109,7 @@ export default class Map extends React.Component {
&& this.state.selectedType.Vegetables
&& this.state.selectedType.Vegetables.map((vegetable, key) => (
<Link
to={`/vegetaux/${this.state.selectedType.id}-${strToSlug(this.state.selectedType.name)}/${vegetable.id}-${strToSlug(vegetable.name)}`}
to={this.createLink(vegetable)}
key={key}
className={`mapMarker ${this.state.selectedVegetable && this.state.selectedVegetable.id === vegetable.id ? 'selected' : ''}`}
style={{ left: `calc(${vegetable.lat}% - 16px)`, top: `calc(${vegetable.lng}% - 16px)` }}

View File

@ -24,6 +24,18 @@ export default class Map extends React.Component {
this.setState(newProps);
}
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 (
<div className="with-margin">
@ -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)}
>
<Link to={`/vegetaux/${this.state.selectedType.id}-${strToSlug(this.state.selectedType.name)}/${vegetable.id}-${strToSlug(vegetable.name)}`}>
<Link to={this.createLink(vegetable)}>
{vegetable.name}
</Link>

View File

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