2020-07-06 08:27:32 -04:00
|
|
|
// @ts-check
|
2018-05-30 12:41:47 -04:00
|
|
|
import React from 'react';
|
|
|
|
import { Sparklines, SparklinesCurve } from 'react-sparklines';
|
2018-06-03 23:15:50 -04:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2021-02-27 19:01:34 -05:00
|
|
|
import PropTypes from 'prop-types';
|
2018-05-30 12:41:47 -04:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2019-01-14 17:29:21 -05:00
|
|
|
import Permalink from './permalink';
|
2020-07-06 08:27:32 -04:00
|
|
|
import ShortNumber from 'mastodon/components/short_number';
|
|
|
|
|
2021-02-27 19:01:34 -05:00
|
|
|
class SilentErrorBoundary extends React.Component {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
error: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidCatch () {
|
|
|
|
this.setState({ error: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
if (this.state.error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.props.children;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-06 08:27:32 -04:00
|
|
|
/**
|
|
|
|
* Used to render counter of how much people are talking about hashtag
|
|
|
|
*
|
|
|
|
* @type {(displayNumber: JSX.Element, pluralReady: number) => JSX.Element}
|
|
|
|
*/
|
|
|
|
const accountsCountRenderer = (displayNumber, pluralReady) => (
|
|
|
|
<FormattedMessage
|
|
|
|
id='trends.counter_by_accounts'
|
|
|
|
defaultMessage='{count, plural, one {{counter} person} other {{counter} people}} talking'
|
|
|
|
values={{
|
|
|
|
count: pluralReady,
|
|
|
|
counter: <strong>{displayNumber}</strong>,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2018-05-30 12:41:47 -04:00
|
|
|
|
|
|
|
const Hashtag = ({ hashtag }) => (
|
|
|
|
<div className='trends__item'>
|
|
|
|
<div className='trends__item__name'>
|
2020-07-06 08:27:32 -04:00
|
|
|
<Permalink
|
|
|
|
href={hashtag.get('url')}
|
2021-09-25 23:46:13 -04:00
|
|
|
to={`/tags/${hashtag.get('name')}`}
|
2020-07-06 08:27:32 -04:00
|
|
|
>
|
2018-05-30 12:41:47 -04:00
|
|
|
#<span>{hashtag.get('name')}</span>
|
2019-01-14 17:29:21 -05:00
|
|
|
</Permalink>
|
2018-05-30 12:41:47 -04:00
|
|
|
|
2020-07-06 08:27:32 -04:00
|
|
|
<ShortNumber
|
|
|
|
value={
|
|
|
|
hashtag.getIn(['history', 0, 'accounts']) * 1 +
|
|
|
|
hashtag.getIn(['history', 1, 'accounts']) * 1
|
|
|
|
}
|
|
|
|
renderer={accountsCountRenderer}
|
|
|
|
/>
|
2018-05-30 12:41:47 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='trends__item__current'>
|
2020-07-06 08:27:32 -04:00
|
|
|
<ShortNumber
|
|
|
|
value={
|
|
|
|
hashtag.getIn(['history', 0, 'uses']) * 1 +
|
|
|
|
hashtag.getIn(['history', 1, 'uses']) * 1
|
|
|
|
}
|
|
|
|
/>
|
2018-05-30 12:41:47 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='trends__item__sparkline'>
|
2021-02-27 19:01:34 -05:00
|
|
|
<SilentErrorBoundary>
|
|
|
|
<Sparklines
|
|
|
|
width={50}
|
|
|
|
height={28}
|
|
|
|
data={hashtag
|
|
|
|
.get('history')
|
|
|
|
.reverse()
|
|
|
|
.map((day) => day.get('uses'))
|
|
|
|
.toArray()}
|
|
|
|
>
|
|
|
|
<SparklinesCurve style={{ fill: 'none' }} />
|
|
|
|
</Sparklines>
|
|
|
|
</SilentErrorBoundary>
|
2018-05-30 12:41:47 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
Hashtag.propTypes = {
|
|
|
|
hashtag: ImmutablePropTypes.map.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Hashtag;
|