import React from 'react'; import PropTypes from 'prop-types'; import Page from '../PageList/Page'; import SearchResultList from './SearchResultList'; // Search.SearchResult export default class SearchResult extends React.Component { isNotSearchedYet() { return !this.props.searchResultMeta.took; } isNotFound() { return this.props.searchingKeyword !== '' && this.props.pages.length === 0; } isError() { if (this.props.searchError !== null) { return true; } return false; } render() { const excludePathString = this.props.tree; //console.log(this.props.searchError); //console.log(this.isError()); if (this.isError()) { return (
Error on searching.
); } if (this.isNotSearchedYet()) { return
; } if (this.isNotFound()) { let under = ''; if (this.props.tree !== '') { under = ` under "${this.props.tree}"`; } return (
No page found with "{this.props.searchingKeyword}"{under}
); } const listView = this.props.pages.map((page) => { const pageId = "#" + page._id; return (
); }); // TODO あとでなんとかする setTimeout(() => { $('#search-result-list > nav').affix({ offset: { top: 120 }}); }, 1200); /* UI あとで考える Found: {this.props.searchResultMeta.total} pages with "{this.props.searchingKeyword}" */ return (
Found {this.props.searchResultMeta.total} pages with "{this.props.searchingKeyword}"
); } } SearchResult.propTypes = { tree: PropTypes.string.isRequired, pages: PropTypes.array.isRequired, searchingKeyword: PropTypes.string.isRequired, searchResultMeta: PropTypes.object.isRequired, }; SearchResult.defaultProps = { tree: '', pages: [], searchingKeyword: '', searchResultMeta: {}, searchError: null, };