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.

73 lines
1.9 KiB

  1. // @ts-check
  2. import React from 'react';
  3. import { Sparklines, SparklinesCurve } from 'react-sparklines';
  4. import { FormattedMessage } from 'react-intl';
  5. import ImmutablePropTypes from 'react-immutable-proptypes';
  6. import Permalink from './permalink';
  7. import ShortNumber from 'mastodon/components/short_number';
  8. /**
  9. * Used to render counter of how much people are talking about hashtag
  10. *
  11. * @type {(displayNumber: JSX.Element, pluralReady: number) => JSX.Element}
  12. */
  13. const accountsCountRenderer = (displayNumber, pluralReady) => (
  14. <FormattedMessage
  15. id='trends.counter_by_accounts'
  16. defaultMessage='{count, plural, one {{counter} person} other {{counter} people}} talking'
  17. values={{
  18. count: pluralReady,
  19. counter: <strong>{displayNumber}</strong>,
  20. }}
  21. />
  22. );
  23. const Hashtag = ({ hashtag }) => (
  24. <div className='trends__item'>
  25. <div className='trends__item__name'>
  26. <Permalink
  27. href={hashtag.get('url')}
  28. to={`/timelines/tag/${hashtag.get('name')}`}
  29. >
  30. #<span>{hashtag.get('name')}</span>
  31. </Permalink>
  32. <ShortNumber
  33. value={
  34. hashtag.getIn(['history', 0, 'accounts']) * 1 +
  35. hashtag.getIn(['history', 1, 'accounts']) * 1
  36. }
  37. renderer={accountsCountRenderer}
  38. />
  39. </div>
  40. <div className='trends__item__current'>
  41. <ShortNumber
  42. value={
  43. hashtag.getIn(['history', 0, 'uses']) * 1 +
  44. hashtag.getIn(['history', 1, 'uses']) * 1
  45. }
  46. />
  47. </div>
  48. <div className='trends__item__sparkline'>
  49. <Sparklines
  50. width={50}
  51. height={28}
  52. data={hashtag
  53. .get('history')
  54. .reverse()
  55. .map((day) => day.get('uses'))
  56. .toArray()}
  57. >
  58. <SparklinesCurve style={{ fill: 'none' }} />
  59. </Sparklines>
  60. </div>
  61. </div>
  62. );
  63. Hashtag.propTypes = {
  64. hashtag: ImmutablePropTypes.map.isRequired,
  65. };
  66. export default Hashtag;