SearchResult.js 3.1 KB

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