2021-10-14 18:44:59 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 15:15:17 +00:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2021-10-14 18:44:59 +00:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
2021-10-14 18:44:59 +00:00
|
|
|
import classNames from 'classnames';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
|
|
|
import api from 'mastodon/api';
|
2023-11-28 18:20:10 +00:00
|
|
|
import { Hashtag } from 'mastodon/components/hashtag';
|
2021-10-14 18:44:59 +00:00
|
|
|
|
2023-05-23 08:52:27 +00:00
|
|
|
export default class Trends extends PureComponent {
|
2021-10-14 18:44:59 +00:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
limit: PropTypes.number.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
loading: true,
|
|
|
|
data: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
const { limit } = this.props;
|
|
|
|
|
2024-05-23 07:30:48 +00:00
|
|
|
api(false).get('/api/v1/admin/trends/tags', { params: { limit } }).then(res => {
|
2021-10-14 18:44:59 +00:00
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
data: res.data,
|
|
|
|
});
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { limit } = this.props;
|
|
|
|
const { loading, data } = this.state;
|
|
|
|
|
|
|
|
let content;
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
content = (
|
|
|
|
<div>
|
|
|
|
{Array.from(Array(limit)).map((_, i) => (
|
|
|
|
<Hashtag key={i} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
content = (
|
|
|
|
<div>
|
|
|
|
{data.map(hashtag => (
|
|
|
|
<Hashtag
|
|
|
|
key={hashtag.name}
|
|
|
|
name={hashtag.name}
|
2023-01-18 15:28:18 +00:00
|
|
|
to={hashtag.id === undefined ? undefined : `/admin/tags/${hashtag.id}`}
|
2021-10-14 18:44:59 +00:00
|
|
|
people={hashtag.history[0].accounts * 1 + hashtag.history[1].accounts * 1}
|
|
|
|
uses={hashtag.history[0].uses * 1 + hashtag.history[1].uses * 1}
|
|
|
|
history={hashtag.history.reverse().map(day => day.uses)}
|
|
|
|
className={classNames(hashtag.requires_review && 'trends__item--requires-review', !hashtag.trendable && !hashtag.requires_review && 'trends__item--disabled')}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='trends trends--compact'>
|
|
|
|
<h4><FormattedMessage id='trends.trending_now' defaultMessage='Trending now' /></h4>
|
|
|
|
|
|
|
|
{content}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|