import React, { PropTypes } from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { connect } from 'react-redux'; import { selectSearchedEntries } from '../reducers'; import { searchEntries as actionSearchEntries, clearSearch as actionClearSearch } from '../actions/search'; import { Loader } from '../components/UI'; import EntryListing from '../components/EntryListing/EntryListing'; class SearchPage extends React.Component { static propTypes = { isFetching: PropTypes.bool, searchEntries: PropTypes.func.isRequired, clearSearch: PropTypes.func.isRequired, searchTerm: PropTypes.string.isRequired, collections: ImmutablePropTypes.seq, entries: ImmutablePropTypes.list, page: PropTypes.number, publicFolder: PropTypes.string, }; componentDidMount() { const { searchTerm, searchEntries } = this.props; searchEntries(searchTerm); } componentWillReceiveProps(nextProps) { if (this.props.searchTerm === nextProps.searchTerm) return; const { searchEntries } = this.props; searchEntries(nextProps.searchTerm); } componentWillUnmount() { this.props.clearSearch(); } handleLoadMore = (page) => { const { searchTerm, searchEntries } = this.props; if (!isNaN(page)) searchEntries(searchTerm, page); }; render() { const { collections, searchTerm, entries, isFetching, page, publicFolder } = this.props; return (