2023-02-27 05:25:59 -08:00
|
|
|
import React, { useState } from 'react';
|
2023-03-06 05:11:58 -08:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-02-27 05:25:59 -08:00
|
|
|
|
|
|
|
import { Carousel, Stack, Text } from 'soapbox/components/ui';
|
|
|
|
import PlaceholderGroupDiscover from 'soapbox/features/placeholder/components/placeholder-group-discover';
|
2023-03-13 13:08:42 -07:00
|
|
|
import { usePopularGroups } from 'soapbox/hooks/api/usePopularGroups';
|
2023-02-27 05:25:59 -08:00
|
|
|
|
2023-03-08 10:22:10 -08:00
|
|
|
import GroupGridItem from './group-grid-item';
|
2023-02-27 05:25:59 -08:00
|
|
|
|
|
|
|
const PopularGroups = () => {
|
2023-03-06 05:11:58 -08:00
|
|
|
const { groups, isFetching, isFetched, isError } = usePopularGroups();
|
|
|
|
const isEmpty = (isFetched && groups.length === 0) || isError;
|
2023-02-27 05:25:59 -08:00
|
|
|
|
|
|
|
const [groupCover, setGroupCover] = useState<HTMLDivElement | null>(null);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Stack space={4}>
|
|
|
|
<Text size='xl' weight='bold'>
|
2023-03-06 05:11:58 -08:00
|
|
|
<FormattedMessage
|
|
|
|
id='groups.discover.popular.title'
|
|
|
|
defaultMessage='Popular Groups'
|
|
|
|
/>
|
2023-02-27 05:25:59 -08:00
|
|
|
</Text>
|
|
|
|
|
2023-03-06 05:11:58 -08:00
|
|
|
{isEmpty ? (
|
|
|
|
<Text theme='muted'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='groups.discover.popular.empty'
|
|
|
|
defaultMessage='Unable to fetch popular groups at this time. Please check back later.'
|
|
|
|
/>
|
|
|
|
</Text>
|
|
|
|
) : (
|
|
|
|
<Carousel
|
|
|
|
itemWidth={250}
|
|
|
|
itemCount={groups.length}
|
|
|
|
controlsHeight={groupCover?.clientHeight}
|
|
|
|
>
|
|
|
|
{({ width }: { width: number }) => (
|
|
|
|
<>
|
|
|
|
{isFetching ? (
|
|
|
|
new Array(20).fill(0).map((_, idx) => (
|
|
|
|
<div
|
|
|
|
className='relative flex shrink-0 flex-col space-y-2 px-0.5'
|
|
|
|
style={{ width: width || 'auto' }}
|
|
|
|
key={idx}
|
|
|
|
>
|
|
|
|
<PlaceholderGroupDiscover />
|
|
|
|
</div>
|
|
|
|
))
|
|
|
|
) : (
|
|
|
|
groups.map((group) => (
|
2023-03-08 10:22:10 -08:00
|
|
|
<GroupGridItem
|
2023-03-06 05:11:58 -08:00
|
|
|
key={group.id}
|
|
|
|
group={group}
|
|
|
|
width={width}
|
|
|
|
ref={setGroupCover}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Carousel>
|
|
|
|
)}
|
2023-02-27 05:25:59 -08:00
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PopularGroups;
|