import { Map as ImmutableMap } from 'immutable'; import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import { useDispatch } from 'react-redux'; import { Widget } from 'soapbox/components/ui'; import { useAppSelector } from 'soapbox/hooks'; import { fetchTrends } from '../../../actions/trends'; import Hashtag from '../../../components/hashtag'; interface ITrendsPanel { limit: number } const TrendsPanel = ({ limit }: ITrendsPanel) => { const dispatch = useDispatch(); const trends: any = useAppSelector((state) => state.trends.get('items')); const sortedTrends = React.useMemo(() => { return trends.sort((a: ImmutableMap, b: ImmutableMap) => { const num_a = Number(a.getIn(['history', 0, 'accounts'])); const num_b = Number(b.getIn(['history', 0, 'accounts'])); return num_b - num_a; }).slice(0, limit); }, [trends, limit]); React.useEffect(() => { dispatch(fetchTrends()); }, []); if (sortedTrends.isEmpty()) { return null; } return ( }> {sortedTrends.map((hashtag: ImmutableMap) => ( ))} ); }; export default TrendsPanel;