61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
var React = require('react'),
|
|
NavigationActions = require('../../actions/navigationActions'),
|
|
Globals = require('../../globals')
|
|
Router = require("react-router"),
|
|
LinkBanner = require('../linkBanner/linkBanner'),
|
|
Link = Router.Link;
|
|
|
|
var SearchStore = require('../../stores/searchStore');
|
|
var SearchActions = require('../../actions/searchActions');
|
|
|
|
var ItemList = require('../items/itemList');
|
|
var SearchResultsPage = React.createClass({
|
|
mixins: [Router.State],
|
|
getInitialState: function() {
|
|
return SearchStore.getSearchResultsState();
|
|
},
|
|
render: function() {
|
|
var content;
|
|
|
|
if (this.state.items.length > 0) {
|
|
content = <ItemList items={this.state.items} />
|
|
} else {
|
|
|
|
content = <div>Nema rezultata za vašu pretragu.</div>
|
|
}
|
|
return (
|
|
<div>
|
|
|
|
<LinkBanner locationName="searchResultPage" />
|
|
<h2>Rezultati pretrage za '{this.state.q}'</h2>
|
|
|
|
{content}
|
|
</div>
|
|
);
|
|
},
|
|
componentWillReceiveProps: function() {
|
|
this.update();
|
|
},
|
|
update: function(){
|
|
var query = this.getQuery();
|
|
SearchActions.getSearchResults(query.q);
|
|
},
|
|
componentDidMount: function() {
|
|
SearchStore.addChangeListener(this._onChange);
|
|
this.update();
|
|
|
|
//CartActions.load();
|
|
},
|
|
componentWillUnmount: function () {
|
|
SearchStore.removeChangeListener(this._onChange);
|
|
},
|
|
_onChange: function() {
|
|
if(this.isMounted()) {
|
|
this.setState(SearchStore.getSearchResultsState());
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
module.exports = SearchResultsPage;
|