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.

41 lines
1.5 KiB

  1. import React from 'react';
  2. import { Sparklines, SparklinesCurve } from 'react-sparklines';
  3. import { Link } from 'react-router-dom';
  4. import { FormattedMessage, FormattedNumber } from 'react-intl';
  5. import ImmutablePropTypes from 'react-immutable-proptypes';
  6. const shortNumberFormat = number => {
  7. if (number < 1000) {
  8. return <FormattedNumber value={number} />;
  9. } else {
  10. return <React.Fragment><FormattedNumber value={number / 1000} maximumFractionDigits={1} />K</React.Fragment>;
  11. }
  12. };
  13. const Hashtag = ({ hashtag }) => (
  14. <div className='trends__item'>
  15. <div className='trends__item__name'>
  16. <Link to={`/timelines/tag/${hashtag.get('name')}`}>
  17. #<span>{hashtag.get('name')}</span>
  18. </Link>
  19. <FormattedMessage id='trends.count_by_accounts' defaultMessage='{count} {rawCount, plural, one {person} other {people}} talking' values={{ rawCount: hashtag.getIn(['history', 0, 'accounts']), count: <strong>{shortNumberFormat(hashtag.getIn(['history', 0, 'accounts']))}</strong> }} />
  20. </div>
  21. <div className='trends__item__current'>
  22. {shortNumberFormat(hashtag.getIn(['history', 0, 'uses']))}
  23. </div>
  24. <div className='trends__item__sparkline'>
  25. <Sparklines width={50} height={28} data={hashtag.get('history').reverse().map(day => day.get('uses')).toArray()}>
  26. <SparklinesCurve style={{ fill: 'none' }} />
  27. </Sparklines>
  28. </div>
  29. </div>
  30. );
  31. Hashtag.propTypes = {
  32. hashtag: ImmutablePropTypes.map.isRequired,
  33. };
  34. export default Hashtag;