Files
old-ribica/front-ui/app/components/search/searchResultsPage.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-03-22 16:16:52 +01:00
var React = require('react'),
NavigationActions = require('../../actions/navigationActions'),
Globals = require('../../globals')
Router = require("react-router"),
2015-03-29 12:46:51 +02:00
LinkBanner = require('../linkBanner/linkBanner'),
2015-03-22 16:16:52 +01:00
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() {
2015-03-23 00:19:48 +01:00
var content;
if (this.state.items.length > 0) {
content = <ItemList items={this.state.items} />
} else {
content = <div>Nema rezultata za vašu pretragu.</div>
}
2015-03-22 16:16:52 +01:00
return (
2015-03-23 00:19:48 +01:00
<div>
2015-03-29 12:46:51 +02:00
<LinkBanner locationName="searchResultPage" />
2015-03-23 00:19:48 +01:00
<h2>Rezultati pretrage za '{this.state.q}'</h2>
2015-03-22 16:16:52 +01:00
2015-03-23 00:19:48 +01:00
{content}
</div>
2015-03-22 16:16:52 +01:00
);
},
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;