Last active
July 26, 2018 13:04
-
-
Save mittsh/0d973b0f7dbda136f99d0f53ef5fcfdf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SearchContainer = (props) => { | |
const { | |
searchText, | |
setSearchText, | |
renderTools | |
} = props | |
return ( | |
<div className={style.input_container}> | |
<input | |
className={style.search_input} | |
type="text" | |
value={searchText} | |
onChange={setSearchText} | |
{...props} | |
/> | |
<ClearButton | |
fn={setSearchText} | |
hidden={!searchText || searchText.length === 0} | |
/> | |
{renderTools ? renderTools() : null} | |
</div> | |
) | |
} | |
const SearchInputContainer = connect(state => ({ | |
searchText: state.search.get('text'), | |
}))((props) => { | |
const { searchText } = props | |
return ( | |
<SearchContainer | |
searchText={searchText} | |
setSearchText={(e) => { setInSearch(['text'], e.target.value, true /* refresh search */) }} | |
placeholder="Quoi…" | |
/> | |
) | |
}) | |
@connect(state => ({ | |
places: getPlaces(state), | |
placeSearchText: state.place_search.get('text'), | |
geo_mode: state.search.get('geo_mode'), | |
})) | |
class SearchLocationContainer extends Component { | |
... | |
renderTools() { | |
const { places, placeSearchText, geo_mode } = this.props | |
const { expanded } = this.state | |
const activePlace = this.getActivePlace() | |
return [ | |
<LocationButton enabled={geo_mode === GEO_MODE_AROUND_ME} />, | |
<div | |
ref={this.setMenuRef} | |
className={expanded ? style.places_container : style.places_container_hidden} | |
> | |
{expanded ? | |
( | |
<PlaceList | |
places={places} | |
activePlace={activePlace} | |
setPlace={this.setPlace} | |
/> | |
) : null} | |
</div> | |
] | |
} | |
render() { | |
const { placeSearchText, geo_mode } = this.props | |
const { expanded } = this.state | |
const activePlace = this.getActivePlace() | |
return ( | |
<SearchContainer | |
searchText={(geo_mode === GEO_MODE_AROUND_ME && !expanded) ? 'Autour de moi' : placeSearchText} | |
setSearchText={(e) => { setInSearch(['text'], e.target.value, true /* refresh search */) }} | |
onChange={onChange} | |
onFocus={this.onInputFocus} | |
onBlur={this.onInputBlur} | |
onKeyDown={this.onInputKeyDown} | |
placeholder="Où…" | |
renderTools={this.renderTools.bind(this)} | |
/> | |
) | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment