闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import { defineMessages, injectIntl, 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/Link';
  7. import ImmutablePureComponent from 'react-immutable-pure-component';
  8. 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. {results.get('accounts').map(accountId => <AccountContainer key={accountId} id={accountId} />)}
  21. </div>
  22. );
  23. }
  24. if (results.get('statuses') && results.get('statuses').size > 0) {
  25. count += results.get('statuses').size;
  26. statuses = (
  27. <div className='search-results__section'>
  28. {results.get('statuses').map(statusId => <StatusContainer key={statusId} id={statusId} />)}
  29. </div>
  30. );
  31. }
  32. if (results.get('hashtags') && results.get('hashtags').size > 0) {
  33. count += results.get('hashtags').size;
  34. hashtags = (
  35. <div className='search-results__section'>
  36. {results.get('hashtags').map(hashtag =>
  37. <Link key={hashtag} className='search-results__hashtag' to={`/timelines/tag/${hashtag}`}>
  38. #{hashtag}
  39. </Link>
  40. )}
  41. </div>
  42. );
  43. }
  44. return (
  45. <div className='search-results'>
  46. <div className='search-results__header'>
  47. <FormattedMessage id='search_results.total' defaultMessage='{count, number} {count, plural, one {result} other {results}}' values={{ count }} />
  48. </div>
  49. {accounts}
  50. {statuses}
  51. {hashtags}
  52. </div>
  53. );
  54. }
  55. }
  56. export default SearchResults;