SearchResult.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React from 'react';
  2. import Page from '../PageList/Page';
  3. import SearchResultList from './SearchResultList';
  4. // Search.SearchResult
  5. export default class SearchResult extends React.Component {
  6. isNotSearchedYet() {
  7. return !this.props.searchResultMeta.took;
  8. }
  9. isNotFound() {
  10. return this.props.searchingKeyword !== '' && this.props.pages.length === 0;
  11. }
  12. render() {
  13. const excludePathString = this.props.tree;
  14. if (this.isNotSearchedYet()) {
  15. return <div />;
  16. }
  17. if (this.isNotFound()) {
  18. let under = '';
  19. if (this.props.tree !== '') {
  20. under = ` under "${this.props.tree}"`;
  21. }
  22. return (
  23. <div className="content-main">
  24. <i className="fa fa-meh-o" /> No page found with "{this.props.searchingKeyword}"{under}
  25. </div>
  26. );
  27. }
  28. const listView = this.props.pages.map((page) => {
  29. const pageId = "#" + page._id;
  30. return (
  31. <Page page={page}
  32. linkTo={pageId}
  33. key={page._id}
  34. excludePathString={excludePathString}
  35. >
  36. <div className="page-list-option">
  37. <a href={page.path}><i className="fa fa-arrow-circle-right" /></a>
  38. </div>
  39. </Page>
  40. );
  41. });
  42. /*
  43. UI あとで考える
  44. <span className="search-result-meta">Found: {this.props.searchResultMeta.total} pages with "{this.props.searchingKeyword}"</span>
  45. */
  46. return (
  47. <div className="content-main">
  48. <div className="search-result row" id="search-result">
  49. <div className="col-md-4 page-list search-result-list" id="search-result-list">
  50. <nav data-spy="affix" data-offset-top="120">
  51. <ul className="page-list-ul nav">
  52. {listView}
  53. </ul>
  54. </nav>
  55. </div>
  56. <div className="col-md-8 search-result-content" id="search-result-content">
  57. <div className="search-result-meta"><i className="fa fa-lightbulb-o" /> Found {this.props.searchResultMeta.total} pages with "{this.props.searchingKeyword}"</div>
  58. <SearchResultList
  59. pages={this.props.pages}
  60. searchingKeyword={this.props.searchingKeyword}
  61. />
  62. </div>
  63. </div>
  64. </div>
  65. );
  66. }
  67. }
  68. SearchResult.propTypes = {
  69. tree: React.PropTypes.string.isRequired,
  70. pages: React.PropTypes.array.isRequired,
  71. searchingKeyword: React.PropTypes.string.isRequired,
  72. searchResultMeta: React.PropTypes.object.isRequired,
  73. };
  74. SearchResult.defaultProps = {
  75. tree: '',
  76. pages: [],
  77. searchingKeyword: '',
  78. searchResultMeta: {},
  79. };