SearchResultList.jsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. return (
  14. <div id={page._id} key={page._id} className="search-result-page mb-5">
  15. <h2><a href={page.path}>{page.path}</a></h2>
  16. { page.tags.length > 0 && (
  17. <span><i className="tag-icon icon-tag"></i> {page.tags.join(', ')}</span>
  18. )}
  19. <RevisionLoader
  20. growiRenderer={this.growiRenderer}
  21. pageId={page._id}
  22. pagePath={page.path}
  23. revisionId={page.revision}
  24. highlightKeywords={this.props.searchingKeyword}
  25. />
  26. </div>
  27. );
  28. });
  29. return (
  30. <div>
  31. {resultList}
  32. </div>
  33. );
  34. }
  35. }
  36. /**
  37. * Wrapper component for using unstated
  38. */
  39. const SearchResultListWrapper = (props) => {
  40. return createSubscribedElement(SearchResultList, props, [AppContainer]);
  41. };
  42. SearchResultList.propTypes = {
  43. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  44. pages: PropTypes.array.isRequired,
  45. searchingKeyword: PropTypes.string.isRequired,
  46. };
  47. SearchResultList.defaultProps = {
  48. };
  49. export default SearchResultListWrapper;