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.

106 lines
3.6 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import { FormattedMessage, defineMessages, injectIntl } from 'react-intl';
  5. import AccountContainer from 'flavours/glitch/containers/account_container';
  6. import StatusContainer from 'flavours/glitch/containers/status_container';
  7. import ImmutablePureComponent from 'react-immutable-pure-component';
  8. import Hashtag from 'flavours/glitch/components/hashtag';
  9. import Icon from 'flavours/glitch/components/icon';
  10. const messages = defineMessages({
  11. dismissSuggestion: { id: 'suggestions.dismiss', defaultMessage: 'Dismiss suggestion' },
  12. });
  13. export default @injectIntl
  14. class SearchResults extends ImmutablePureComponent {
  15. static propTypes = {
  16. results: ImmutablePropTypes.map.isRequired,
  17. suggestions: ImmutablePropTypes.list.isRequired,
  18. fetchSuggestions: PropTypes.func.isRequired,
  19. dismissSuggestion: PropTypes.func.isRequired,
  20. intl: PropTypes.object.isRequired,
  21. };
  22. componentDidMount () {
  23. this.props.fetchSuggestions();
  24. }
  25. render() {
  26. const { intl, results, suggestions, dismissSuggestion } = this.props;
  27. if (results.isEmpty() && !suggestions.isEmpty()) {
  28. return (
  29. <div className='drawer--results'>
  30. <div className='trends'>
  31. <div className='trends__header'>
  32. <i className='fa fa-user-plus fa-fw' />
  33. <FormattedMessage id='suggestions.header' defaultMessage='You might be interested in…' />
  34. </div>
  35. {suggestions && suggestions.map(accountId => (
  36. <AccountContainer
  37. key={accountId}
  38. id={accountId}
  39. actionIcon='times'
  40. actionTitle={intl.formatMessage(messages.dismissSuggestion)}
  41. onActionClick={dismissSuggestion}
  42. />
  43. ))}
  44. </div>
  45. </div>
  46. );
  47. }
  48. let accounts, statuses, hashtags;
  49. let count = 0;
  50. if (results.get('accounts') && results.get('accounts').size > 0) {
  51. count += results.get('accounts').size;
  52. accounts = (
  53. <section>
  54. <h5><Icon icon='users' fixedWidth /><FormattedMessage id='search_results.accounts' defaultMessage='People' /></h5>
  55. {results.get('accounts').map(accountId => <AccountContainer id={accountId} key={accountId} />)}
  56. </section>
  57. );
  58. }
  59. if (results.get('statuses') && results.get('statuses').size > 0) {
  60. count += results.get('statuses').size;
  61. statuses = (
  62. <section>
  63. <h5><Icon icon='quote-right' fixedWidth /><FormattedMessage id='search_results.statuses' defaultMessage='Toots' /></h5>
  64. {results.get('statuses').map(statusId => <StatusContainer id={statusId} key={statusId}/>)}
  65. </section>
  66. );
  67. }
  68. if (results.get('hashtags') && results.get('hashtags').size > 0) {
  69. count += results.get('hashtags').size;
  70. hashtags = (
  71. <section>
  72. <h5><Icon icon='hashtag' fixedWidth /><FormattedMessage id='search_results.hashtags' defaultMessage='Hashtags' /></h5>
  73. {results.get('hashtags').map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)}
  74. </section>
  75. );
  76. }
  77. // The result.
  78. return (
  79. <div className='drawer--results'>
  80. <header className='search-results__header'>
  81. <Icon icon='search' fixedWidth />
  82. <FormattedMessage id='search_results.total' defaultMessage='{count, number} {count, plural, one {result} other {results}}' values={{ count }} />
  83. </header>
  84. {accounts}
  85. {statuses}
  86. {hashtags}
  87. </div>
  88. );
  89. };
  90. }