SearchResultList.jsx 1.6 KB

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