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

View file

@ -40,6 +40,8 @@ export default class Search extends React.Component {
this.setState({ this.setState({
selectedType: { selectedType: {
Vegetables: res.data.rows, 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, vegetables: res.data.rows,
}); });