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.

110 lines
3.6 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  4. import Icon from 'mastodon/components/icon';
  5. const tooltips = defineMessages({
  6. mentions: { id: 'notifications.filter.mentions', defaultMessage: 'Mentions' },
  7. favourites: { id: 'notifications.filter.favourites', defaultMessage: 'Favourites' },
  8. boosts: { id: 'notifications.filter.boosts', defaultMessage: 'Boosts' },
  9. polls: { id: 'notifications.filter.polls', defaultMessage: 'Poll results' },
  10. follows: { id: 'notifications.filter.follows', defaultMessage: 'Follows' },
  11. statuses: { id: 'notifications.filter.statuses', defaultMessage: 'Updates from people you follow' },
  12. });
  13. export default @injectIntl
  14. class FilterBar extends React.PureComponent {
  15. static propTypes = {
  16. selectFilter: PropTypes.func.isRequired,
  17. selectedFilter: PropTypes.string.isRequired,
  18. advancedMode: PropTypes.bool.isRequired,
  19. intl: PropTypes.object.isRequired,
  20. };
  21. onClick (notificationType) {
  22. return () => this.props.selectFilter(notificationType);
  23. }
  24. render () {
  25. const { selectedFilter, advancedMode, intl } = this.props;
  26. const renderedElement = !advancedMode ? (
  27. <div className='notification__filter-bar'>
  28. <button
  29. className={selectedFilter === 'all' ? 'active' : ''}
  30. onClick={this.onClick('all')}
  31. >
  32. <FormattedMessage
  33. id='notifications.filter.all'
  34. defaultMessage='All'
  35. />
  36. </button>
  37. <button
  38. className={selectedFilter === 'mention' ? 'active' : ''}
  39. onClick={this.onClick('mention')}
  40. >
  41. <FormattedMessage
  42. id='notifications.filter.mentions'
  43. defaultMessage='Mentions'
  44. />
  45. </button>
  46. </div>
  47. ) : (
  48. <div className='notification__filter-bar'>
  49. <button
  50. className={selectedFilter === 'all' ? 'active' : ''}
  51. onClick={this.onClick('all')}
  52. >
  53. <FormattedMessage
  54. id='notifications.filter.all'
  55. defaultMessage='All'
  56. />
  57. </button>
  58. <button
  59. className={selectedFilter === 'mention' ? 'active' : ''}
  60. onClick={this.onClick('mention')}
  61. title={intl.formatMessage(tooltips.mentions)}
  62. >
  63. <Icon id='reply-all' fixedWidth />
  64. </button>
  65. <button
  66. className={selectedFilter === 'favourite' ? 'active' : ''}
  67. onClick={this.onClick('favourite')}
  68. title={intl.formatMessage(tooltips.favourites)}
  69. >
  70. <Icon id='star' fixedWidth />
  71. </button>
  72. <button
  73. className={selectedFilter === 'reblog' ? 'active' : ''}
  74. onClick={this.onClick('reblog')}
  75. title={intl.formatMessage(tooltips.boosts)}
  76. >
  77. <Icon id='retweet' fixedWidth />
  78. </button>
  79. <button
  80. className={selectedFilter === 'poll' ? 'active' : ''}
  81. onClick={this.onClick('poll')}
  82. title={intl.formatMessage(tooltips.polls)}
  83. >
  84. <Icon id='tasks' fixedWidth />
  85. </button>
  86. <button
  87. className={selectedFilter === 'status' ? 'active' : ''}
  88. onClick={this.onClick('status')}
  89. title={intl.formatMessage(tooltips.statuses)}
  90. >
  91. <Icon id='home' fixedWidth />
  92. </button>
  93. <button
  94. className={selectedFilter === 'follow' ? 'active' : ''}
  95. onClick={this.onClick('follow')}
  96. title={intl.formatMessage(tooltips.follows)}
  97. >
  98. <Icon id='user-plus' fixedWidth />
  99. </button>
  100. </div>
  101. );
  102. return renderedElement;
  103. }
  104. }