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.

102 lines
3.3 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. });
  12. export default @injectIntl
  13. class FilterBar extends React.PureComponent {
  14. static propTypes = {
  15. selectFilter: PropTypes.func.isRequired,
  16. selectedFilter: PropTypes.string.isRequired,
  17. advancedMode: PropTypes.bool.isRequired,
  18. intl: PropTypes.object.isRequired,
  19. };
  20. onClick (notificationType) {
  21. return () => this.props.selectFilter(notificationType);
  22. }
  23. render () {
  24. const { selectedFilter, advancedMode, intl } = this.props;
  25. const renderedElement = !advancedMode ? (
  26. <div className='notification__filter-bar'>
  27. <button
  28. className={selectedFilter === 'all' ? 'active' : ''}
  29. onClick={this.onClick('all')}
  30. >
  31. <FormattedMessage
  32. id='notifications.filter.all'
  33. defaultMessage='All'
  34. />
  35. </button>
  36. <button
  37. className={selectedFilter === 'mention' ? 'active' : ''}
  38. onClick={this.onClick('mention')}
  39. >
  40. <FormattedMessage
  41. id='notifications.filter.mentions'
  42. defaultMessage='Mentions'
  43. />
  44. </button>
  45. </div>
  46. ) : (
  47. <div className='notification__filter-bar'>
  48. <button
  49. className={selectedFilter === 'all' ? 'active' : ''}
  50. onClick={this.onClick('all')}
  51. >
  52. <FormattedMessage
  53. id='notifications.filter.all'
  54. defaultMessage='All'
  55. />
  56. </button>
  57. <button
  58. className={selectedFilter === 'mention' ? 'active' : ''}
  59. onClick={this.onClick('mention')}
  60. title={intl.formatMessage(tooltips.mentions)}
  61. >
  62. <Icon id='comments' fixedWidth />
  63. </button>
  64. <button
  65. className={selectedFilter === 'favourite' ? 'active' : ''}
  66. onClick={this.onClick('favourite')}
  67. title={intl.formatMessage(tooltips.favourites)}
  68. >
  69. <Icon id='heart' fixedWidth />
  70. </button>
  71. <button
  72. className={selectedFilter === 'reblog' ? 'active' : ''}
  73. onClick={this.onClick('reblog')}
  74. title={intl.formatMessage(tooltips.boosts)}
  75. >
  76. <Icon id='retweet' fixedWidth />
  77. </button>
  78. <button
  79. className={selectedFilter === 'poll' ? 'active' : ''}
  80. onClick={this.onClick('poll')}
  81. title={intl.formatMessage(tooltips.polls)}
  82. >
  83. <Icon id='tasks' fixedWidth />
  84. </button>
  85. <button
  86. className={selectedFilter === 'follow' ? 'active' : ''}
  87. onClick={this.onClick('follow')}
  88. title={intl.formatMessage(tooltips.follows)}
  89. >
  90. <Icon id='user-plus' fixedWidth />
  91. </button>
  92. </div>
  93. );
  94. return renderedElement;
  95. }
  96. }