soapbox/app/soapbox/components/hashtag.tsx

60 wiersze
1.9 KiB
TypeScript
Czysty Zwykły widok Historia

2020-03-27 20:59:38 +00:00
import React from 'react';
import { FormattedMessage } from 'react-intl';
2022-03-21 18:09:01 +00:00
import { useSelector } from 'react-redux';
import { Sparklines, SparklinesCurve } from 'react-sparklines';
2022-03-21 18:09:01 +00:00
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
2020-03-27 20:59:38 +00:00
import { shortNumberFormat } from '../utils/numbers';
2022-01-10 22:01:24 +00:00
import Permalink from './permalink';
2022-03-21 18:09:01 +00:00
import { HStack, Stack, Text } from './ui';
2020-03-27 20:59:38 +00:00
2022-04-28 01:01:31 +00:00
import type { Map as ImmutableMap } from 'immutable';
interface IHashtag {
hashtag: ImmutableMap<string, any>,
}
const Hashtag: React.FC<IHashtag> = ({ hashtag }) => {
const count = Number(hashtag.getIn(['history', 0, 'accounts']));
2022-03-21 18:09:01 +00:00
const brandColor = useSelector((state) => getSoapboxConfig(state).get('brandColor'));
2020-03-27 20:59:38 +00:00
return (
2022-04-07 15:55:15 +00:00
<HStack alignItems='center' justifyContent='between' data-testid='hashtag'>
2022-03-21 18:09:01 +00:00
<Stack>
<Permalink href={hashtag.get('url')} to={`/tags/${hashtag.get('name')}`} className='hover:underline'>
<Text tag='span' size='sm' weight='semibold'>#{hashtag.get('name')}</Text>
</Permalink>
{hashtag.get('history') && (
2022-03-21 18:09:01 +00:00
<Text theme='muted' size='sm'>
<FormattedMessage
id='trends.count_by_accounts'
defaultMessage='{count} {rawCount, plural, one {person} other {people}} talking'
values={{
rawCount: count,
count: <strong>{shortNumberFormat(count)}</strong>,
}}
/>
2022-03-21 18:09:01 +00:00
</Text>
)}
2022-03-21 18:09:01 +00:00
</Stack>
2020-03-27 20:59:38 +00:00
{hashtag.get('history') && (
2022-03-21 18:09:01 +00:00
<div className='w-[40px]'>
<Sparklines
width={40}
height={28}
2022-04-28 01:01:31 +00:00
data={hashtag.get('history').reverse().map((day: ImmutableMap<string, any>) => day.get('uses')).toArray()}
2022-03-21 18:09:01 +00:00
>
<SparklinesCurve style={{ fill: 'none' }} color={brandColor} />
</Sparklines>
</div>
)}
2022-03-21 18:09:01 +00:00
</HStack>
);
};
2020-03-27 20:59:38 +00:00
export default Hashtag;