SearchResultList.jsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import RevisionLoader from '../Page/RevisionLoader';
  4. import AppContainer from '../../services/AppContainer';
  5. import { createSubscribedElement } from '../UnstatedUtils';
  6. class SearchResultList extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. this.growiRenderer = this.props.appContainer.getRenderer('searchresult');
  10. }
  11. render() {
  12. const resultList = this.props.pages.map((page) => {
  13. const showTags = (page.tags != null) && (page.tags.length > 0);
  14. return (
  15. // Add prefix 'id_' in id attr, because scrollspy of bootstrap doesn't work when the first letter of id of target component is numeral.
  16. <div id={`id_${page._id}`} key={page._id} className="search-result-page mb-5">
  17. <h2>
  18. <a href={page.path} className="text-break">{page.path}</a>
  19. { showTags && (
  20. <div className="mt-1 small"><i className="tag-icon icon-tag"></i> {page.tags.join(', ')}</div>
  21. )}
  22. </h2>
  23. <RevisionLoader
  24. growiRenderer={this.growiRenderer}
  25. pageId={page._id}
  26. pagePath={page.path}
  27. revisionId={page.revision}
  28. highlightKeywords={this.props.searchingKeyword}
  29. />
  30. </div>
  31. );
  32. });
  33. return (
  34. <div>
  35. {resultList}
  36. </div>
  37. );
  38. }
  39. }
  40. /**
  41. * Wrapper component for using unstated
  42. */
  43. const SearchResultListWrapper = (props) => {
  44. return createSubscribedElement(SearchResultList, props, [AppContainer]);
  45. };
  46. SearchResultList.propTypes = {
  47. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  48. pages: PropTypes.array.isRequired,
  49. searchingKeyword: PropTypes.string.isRequired,
  50. };
  51. SearchResultList.defaultProps = {
  52. };
  53. export default SearchResultListWrapper;