SearchResult.js 3.1 KB

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