basic version of search implemented
This commit is contained in:
46
front-ui/app/components/shared/searchBox.js
Normal file
46
front-ui/app/components/shared/searchBox.js
Normal file
@@ -0,0 +1,46 @@
|
||||
var React = require('react'),
|
||||
Router = require('react-router');
|
||||
|
||||
var NavigationActions = require('../../actions/navigationActions');
|
||||
var SearchActions = require('../../actions/searchActions');
|
||||
var SearchStore = require('../../stores/searchStore');
|
||||
|
||||
var SearchBox = React.createClass({
|
||||
getInitialState: function() {
|
||||
return SearchStore.getSearchBoxState();
|
||||
},
|
||||
onSearchClick: function(e) {
|
||||
NavigationActions.goToSearchResults(this.state.q);
|
||||
e.preventDefault();
|
||||
},
|
||||
componentDidMount: function() {
|
||||
SearchStore.addChangeListener(this.onSearchStoreChange);
|
||||
},
|
||||
componentWillUnmount: function() {
|
||||
SearchStore.removeChangeListener(this.onSearchStoreChange);
|
||||
},
|
||||
onSearchStoreChange: function() {
|
||||
if(this.isMounted()) {
|
||||
this.setState(SearchStore.getSearchBoxState());
|
||||
}
|
||||
},
|
||||
onSearchBoxChange: function(e) {
|
||||
SearchActions.searchBoxChange(e.currentTarget.value);
|
||||
},
|
||||
onKeyPress: function(e) {
|
||||
var enterKeyCode = 13;
|
||||
if(e.which == enterKeyCode) {
|
||||
NavigationActions.goToSearchResults(this.state.q);
|
||||
}
|
||||
},
|
||||
render: function() {
|
||||
return (<div className="input-group">
|
||||
<input type="text" onKeyPress={this.onKeyPress} className="form-control" value={this.state.q} onChange={this.onSearchBoxChange} placeholder="Pretraga"> </input>
|
||||
<span className="input-group-btn">
|
||||
<button className="btn btn-default" type="button" onClick={this.onSearchClick}>Traži</button>
|
||||
</span>
|
||||
</div>)
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = SearchBox;
|
||||
Reference in New Issue
Block a user