Merge branch 'improve-trends' into 'develop'
Improve Trends Panel See merge request soapbox-pub/soapbox!1831
This commit is contained in:
commit
e0fd99f2db
5 changed files with 62 additions and 10 deletions
|
@ -0,0 +1,21 @@
|
|||
import React from 'react';
|
||||
|
||||
import { Stack } from 'soapbox/components/ui';
|
||||
|
||||
import { randomIntFromInterval, generateText } from '../utils';
|
||||
|
||||
export default ({ limit }: { limit: number }) => {
|
||||
const trend = randomIntFromInterval(6, 3);
|
||||
const stat = randomIntFromInterval(10, 3);
|
||||
|
||||
return (
|
||||
<>
|
||||
{new Array(limit).fill(undefined).map((_, idx) => (
|
||||
<Stack key={idx} className='animate-pulse text-primary-200 dark:text-primary-700'>
|
||||
<p>{generateText(trend)}</p>
|
||||
<p>{generateText(stat)}</p>
|
||||
</Stack>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -1,26 +1,57 @@
|
|||
import * as React from 'react';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { setFilter } from 'soapbox/actions/search';
|
||||
import Hashtag from 'soapbox/components/hashtag';
|
||||
import { Widget } from 'soapbox/components/ui';
|
||||
import { Text, Widget } from 'soapbox/components/ui';
|
||||
import PlaceholderSidebarTrends from 'soapbox/features/placeholder/components/placeholder-sidebar-trends';
|
||||
import { useAppDispatch } from 'soapbox/hooks';
|
||||
import useTrends from 'soapbox/queries/trends';
|
||||
|
||||
interface ITrendsPanel {
|
||||
limit: number
|
||||
}
|
||||
|
||||
const messages = defineMessages({
|
||||
viewAll: {
|
||||
id: 'trendsPanel.viewAll',
|
||||
defaultMessage: 'View all',
|
||||
},
|
||||
});
|
||||
|
||||
const TrendsPanel = ({ limit }: ITrendsPanel) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const intl = useIntl();
|
||||
|
||||
const { data: trends, isFetching } = useTrends();
|
||||
|
||||
if (trends?.length === 0 || isFetching) {
|
||||
const setHashtagsFilter = () => {
|
||||
dispatch(setFilter('hashtags'));
|
||||
};
|
||||
|
||||
if (!isFetching && !trends?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Widget title={<FormattedMessage id='trends.title' defaultMessage='Trends' />}>
|
||||
{trends?.slice(0, limit).map((hashtag) => (
|
||||
<Hashtag key={hashtag.name} hashtag={hashtag} />
|
||||
))}
|
||||
<Widget
|
||||
title={<FormattedMessage id='trends.title' defaultMessage='Trends' />}
|
||||
action={
|
||||
<Link to='/search' onClick={setHashtagsFilter}>
|
||||
<Text tag='span' theme='primary' size='sm' className='hover:underline'>
|
||||
{intl.formatMessage(messages.viewAll)}
|
||||
</Text>
|
||||
</Link>
|
||||
}
|
||||
>
|
||||
{isFetching ? (
|
||||
<PlaceholderSidebarTrends limit={limit} />
|
||||
) : (
|
||||
trends?.slice(0, limit).map((hashtag) => (
|
||||
<Hashtag key={hashtag.name} hashtag={hashtag} />
|
||||
))
|
||||
)}
|
||||
</Widget>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -36,7 +36,7 @@ const DefaultPage: React.FC = ({ children }) => {
|
|||
)}
|
||||
{features.trends && (
|
||||
<BundleContainer fetchComponent={TrendsPanel}>
|
||||
{Component => <Component limit={3} key='trends-panel' />}
|
||||
{Component => <Component limit={5} key='trends-panel' />}
|
||||
</BundleContainer>
|
||||
)}
|
||||
{me && features.suggestions && (
|
||||
|
|
|
@ -82,7 +82,7 @@ const HomePage: React.FC = ({ children }) => {
|
|||
)}
|
||||
{features.trends && (
|
||||
<BundleContainer fetchComponent={TrendsPanel}>
|
||||
{Component => <Component limit={3} />}
|
||||
{Component => <Component limit={5} />}
|
||||
</BundleContainer>
|
||||
)}
|
||||
{hasPatron && (
|
||||
|
|
|
@ -40,7 +40,7 @@ const StatusPage: React.FC<IStatusPage> = ({ children }) => {
|
|||
)}
|
||||
{features.trends && (
|
||||
<BundleContainer fetchComponent={TrendsPanel}>
|
||||
{Component => <Component limit={3} key='trends-panel' />}
|
||||
{Component => <Component limit={5} key='trends-panel' />}
|
||||
</BundleContainer>
|
||||
)}
|
||||
{me && features.suggestions && (
|
||||
|
|
Loading…
Reference in a new issue