logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

search_results.js (2350B)


  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import { FormattedMessage } from 'react-intl';
  4. import AccountContainer from '../../../containers/account_container';
  5. import StatusContainer from '../../../containers/status_container';
  6. import { Link } from 'react-router-dom';
  7. import ImmutablePureComponent from 'react-immutable-pure-component';
  8. export default class SearchResults extends ImmutablePureComponent {
  9. static propTypes = {
  10. results: ImmutablePropTypes.map.isRequired,
  11. };
  12. render () {
  13. const { results } = this.props;
  14. let accounts, statuses, hashtags;
  15. let count = 0;
  16. if (results.get('accounts') && results.get('accounts').size > 0) {
  17. count += results.get('accounts').size;
  18. accounts = (
  19. <div className='search-results__section'>
  20. <h5><FormattedMessage id='search_results.accounts' defaultMessage='People' /></h5>
  21. {results.get('accounts').map(accountId => <AccountContainer key={accountId} id={accountId} />)}
  22. </div>
  23. );
  24. }
  25. if (results.get('statuses') && results.get('statuses').size > 0) {
  26. count += results.get('statuses').size;
  27. statuses = (
  28. <div className='search-results__section'>
  29. <h5><FormattedMessage id='search_results.statuses' defaultMessage='Toots' /></h5>
  30. {results.get('statuses').map(statusId => <StatusContainer key={statusId} id={statusId} />)}
  31. </div>
  32. );
  33. }
  34. if (results.get('hashtags') && results.get('hashtags').size > 0) {
  35. count += results.get('hashtags').size;
  36. hashtags = (
  37. <div className='search-results__section'>
  38. <h5><FormattedMessage id='search_results.hashtags' defaultMessage='Hashtags' /></h5>
  39. {results.get('hashtags').map(hashtag => (
  40. <Link key={hashtag} className='search-results__hashtag' to={`/timelines/tag/${hashtag}`}>
  41. #{hashtag}
  42. </Link>
  43. ))}
  44. </div>
  45. );
  46. }
  47. return (
  48. <div className='search-results'>
  49. <div className='search-results__header'>
  50. <FormattedMessage id='search_results.total' defaultMessage='{count, number} {count, plural, one {result} other {results}}' values={{ count }} />
  51. </div>
  52. {accounts}
  53. {statuses}
  54. {hashtags}
  55. </div>
  56. );
  57. }
  58. }