Port Mastodon's hashtag stats thing to glitch-soc. This doesn't change how hashtags are ordered, and doesn't add a trending hashtags section, but it does change how hashtag searches are rendered, displaying a trend line alongside each hashtag.main
parent
360fbf1bd4
commit
801919fc9b
@ -0,0 +1,34 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Sparklines, SparklinesCurve } from 'react-sparklines';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
|
import { shortNumberFormat } from 'flavours/glitch/util/numbers';
|
||||||
|
|
||||||
|
const Hashtag = ({ hashtag }) => (
|
||||||
|
<div className='trends__item'>
|
||||||
|
<div className='trends__item__name'>
|
||||||
|
<Link to={`/timelines/tag/${hashtag.get('name')}`}>
|
||||||
|
#<span>{hashtag.get('name')}</span>
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<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> }} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='trends__item__current'>
|
||||||
|
{shortNumberFormat(hashtag.getIn(['history', 0, 'uses']))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='trends__item__sparkline'>
|
||||||
|
<Sparklines width={50} height={28} data={hashtag.get('history').reverse().map(day => day.get('uses')).toArray()}>
|
||||||
|
<SparklinesCurve style={{ fill: 'none' }} />
|
||||||
|
</Sparklines>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
Hashtag.propTypes = {
|
||||||
|
hashtag: ImmutablePropTypes.map.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Hashtag;
|
@ -0,0 +1,10 @@
|
|||||||
|
import React, { Fragment } from 'react';
|
||||||
|
import { FormattedNumber } from 'react-intl';
|
||||||
|
|
||||||
|
export const shortNumberFormat = number => {
|
||||||
|
if (number < 1000) {
|
||||||
|
return <FormattedNumber value={number} />;
|
||||||
|
} else {
|
||||||
|
return <Fragment><FormattedNumber value={number / 1000} maximumFractionDigits={1} />K</Fragment>;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in new issue