soapbox/app/soapbox/components/hashtag.tsx

56 wiersze
1.6 KiB
TypeScript
Czysty Zwykły widok Historia

2020-03-27 20:59:38 +00:00
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { Link } from 'react-router-dom';
import { Sparklines, SparklinesCurve } from 'react-sparklines';
2020-03-27 20:59:38 +00:00
import { shortNumberFormat } from '../utils/numbers';
2022-03-21 18:09:01 +00:00
import { HStack, Stack, Text } from './ui';
2020-03-27 20:59:38 +00:00
import type { Tag } from 'soapbox/types/entities';
2022-04-28 01:01:31 +00:00
interface IHashtag {
hashtag: Tag
2022-04-28 01:01:31 +00:00
}
const Hashtag: React.FC<IHashtag> = ({ hashtag }) => {
const count = Number(hashtag.history?.get(0)?.accounts);
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>
<Link to={`/tags/${hashtag.name}`} className='hover:underline'>
<Text tag='span' size='sm' weight='semibold'>#{hashtag.name}</Text>
</Link>
{hashtag.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.history && (
2022-05-17 16:47:32 +00:00
<div className='w-[40px]' data-testid='sparklines'>
2022-03-21 18:09:01 +00:00
<Sparklines
width={40}
height={28}
data={hashtag.history.reverse().map((day) => +day.uses).toArray()}
2022-03-21 18:09:01 +00:00
>
<SparklinesCurve style={{ fill: 'none' }} color='#818cf8' />
</Sparklines>
</div>
)}
2022-03-21 18:09:01 +00:00
</HStack>
);
};
2020-03-27 20:59:38 +00:00
export default Hashtag;